Skip to content

Commit

Permalink
v.1.1.1
Browse files Browse the repository at this point in the history
Joomla 4 support
  • Loading branch information
sergeytolkachyov authored Apr 9, 2022
1 parent 17ef2a4 commit b36045a
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 44 deletions.
4 changes: 2 additions & 2 deletions fields/plugininfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ protected function getLabel()

?>
<div class="wt-b24-plugin-info">
<div class="plugin-info-img span2">
<div class="plugin-info-img span2 col-12">
<a href="https://web-tolk.ru" target="_blank">
<svg width="200" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
Expand All @@ -75,7 +75,7 @@ protected function getLabel()
</svg>
</a>
</div>
<div style="padding: 0px 15px;" class="span10">
<div style="padding: 0px 15px;" class="span10 col-10">
<span class="label label-success">v.<?php echo $wt_plugin_info->version; ?></span>
<?php echo Text::_("PLG_WT_ADD_PRODUCTS_INFO_TO_JOOMLA_SCRIPT_OPTIONS_DESC"); ?>
</div>
Expand Down
62 changes: 45 additions & 17 deletions script.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Joomla\CMS\Installer\InstallerHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\PluginHelper;

use Joomla\CMS\Version;
/**
* Script file of HelloWorld component.
*
Expand Down Expand Up @@ -96,29 +96,57 @@ public function preflight($type, $parent)
*
* @return void
*/
function postflight($type, $parent)
{
function postflight($type, $installer)
{


$jversion = new Version();

// only for Joomla 3.x

if (version_compare($jversion->getShortVersion(), '4.0', '<')) {

$element = strtoupper($installer->get("element")); // ex. "$parent"
$class = 'span';
$web_tolk_site_icon = "<i class='icon-share-alt'></i>";

} else {

$element = strtoupper($installer->getElement());
$class = 'col-';
$web_tolk_site_icon = '';
}

$smile = '';
if($type != 'uninstall'){
$smiles = ['&#9786;','&#128512;','&#128521;','&#128525;','&#128526;','&#128522;','&#128591;'];
$smile_key = array_rand($smiles, 1);
$smile = $smiles[$smile_key];
}

echo "
<div class='row bg-white' style='margin:25px auto; border:1px solid rgba(0,0,0,0.125); box-shadow:0px 0px 10px rgba(0,0,0,0.125); padding: 10px 20px;'>
<div class='".$class."8 p-2'>
<h2>".$smile.Text::_("PLG_".$element."_AFTER_".strtoupper($type))." <br/>".Text::_("PLG_".$element)."</h2>
".Text::_("PLG_".$element."_DESC");

<div class='row' style='margin:25px auto; border:1px solid rgba(0,0,0,0.125); box-shadow:0px 0px 10px rgba(0,0,0,0.125); padding: 10px 20px;'>
<div class='span8 control-group' id='wt_download_id_form_wrapper'>
<h2>".Text::_("PLG_".strtoupper($parent->get("element"))."_AFTER_".strtoupper($type))." <br/>".Text::_("PLG_".strtoupper($parent->get("element")))."</h2>
".Text::_("PLG_".strtoupper($parent->get("element"))."_DESC");


echo Text::_("PLG_".strtoupper($parent->get("element"))."_WHATS_NEW");

echo Text::_("PLG_".$element."_WHATS_NEW");

echo "</div>
<div class='span4' style='display:flex; flex-direction:column; justify-content:center;'>
<img width='200px' src='https://web-tolk.ru/web_tolk_logo_wide.png'>
<div class='".$class."4' style='display:flex; flex-direction:column; justify-content:center;'>
<img width='200' src='https://web-tolk.ru/web_tolk_logo_wide.png'>
<p>Joomla Extensions</p>
<p><a class='btn' href='https://web-tolk.ru' target='_blank'><i class='icon-share-alt'></i> https://web-tolk.ru</a> <a class='btn' href='mailto:[email protected]'><i class='icon-envelope'></i> [email protected]</a></p>
".Text::_("PLG_".strtoupper($parent->get("element"))."_MAYBE_INTERESTING")."
<p class='btn-group'>
<a class='btn btn-sm btn-outline-primary' href='https://web-tolk.ru' target='_blank'>".$web_tolk_site_icon." https://web-tolk.ru</a>
<a class='btn btn-sm btn-outline-primary' href='mailto:[email protected]'><i class='icon-envelope'></i> [email protected]</a>
</p>
<p><a class='btn btn-sm btn-outline-info' href='https://t.me/joomlaru' target='_blank'>Joomla Russian Community in Telegram</a></p>
".Text::_("PLG_".$element."_MAYBE_INTERESTING")."
</div>
";
}
";

}
}
96 changes: 71 additions & 25 deletions wt_add_products_info_to_joomla_script_options.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
defined('_JEXEC') or die;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Factory;
use Joomla\CMS\Version;


/*
Expand All @@ -26,16 +27,7 @@
class PlgJshoppingproductsWt_add_products_info_to_joomla_script_options extends CMSPlugin
{

/**
* Class Constructor
* @param object $subject
* @param array $config
*/
public function __construct( & $subject, $config )
{
parent::__construct( $subject, $config );
$this->loadLanguage();
}
protected $autoloadLanguage = true;

/**
* Method to add products info to Joomla scrtipt options to access its via javascript Joomla.getOptions('jshop_products_details')
Expand All @@ -48,14 +40,21 @@ public function __construct( & $subject, $config )
*/
public function onAfterDisplayProduct(&$product)
{
$jShopConfig = JSFactory::getConfig();
$jversion = new Version();
if (version_compare($jversion->getShortVersion(), '4.0', '<')) {
// only for Joomla 3.x
$jshopConfig = JSFactory::getConfig();
} else {
// Joomla 4
$jshopConfig = \JSFactory::getConfig();
}

$product_info = array();
if($this->params->get('product_view_show_product_name',1) == 1){
$product_info['product_name'] = $product->name;
}
if($this->params->get('product_view_show_product_image',1) == 1){
$product_info['product_image_url'] = $jShopConfig->image_product_live_path.'/'.$product->image;
$product_info['product_image_url'] = $jshopConfig->image_product_live_path.'/'.$product->image;
}
if($this->params->get('product_view_show_product_ean',1) == 1){
$product_info['ean'] = $product->product_ean;
Expand All @@ -67,16 +66,32 @@ public function onAfterDisplayProduct(&$product)
$product_info['quantity'] = $product->product_quantity;
}
if($this->params->get('product_view_show_product_old_price',1) == 1){
$product_info['old_price'] = formatprice($product->product_old_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info['old_price'] = formatprice($product->product_old_price);
} else {
$product_info['old_price'] = \JSHelper::formatprice($product->product_old_price);
}
}

if($this->params->get('product_view_show_product_price',1) == 1 && $this->params->get('product_view_show_product_zero_price',0) == 1){
$product_info['price'] = formatprice($product->product_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info['price'] = formatprice($product->product_price);
} else {
$product_info['price'] = \JSHelper::formatprice($product->product_price);
}
}


if($this->params->get('product_view_show_product_min_price',1) == 1){
$product_info['min_price'] = formatprice($product->min_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info['min_price'] = formatprice($product->min_price);
} else {
$product_info['min_price'] = \JSHelper::formatprice($product->min_price);
}

}
if($this->params->get('product_view_show_product_delivery_time',1) == 1){
$product_info['delivery_time'] = $product->delivery_time;
Expand All @@ -93,6 +108,8 @@ public function onAfterDisplayProduct(&$product)

public function onBeforeDisplayProductListView($view, &$productlist)
{
$jversion = new Version();

$product_info = array();
if(count((array)$productlist->products) > 0){
foreach($productlist->products as $product){
Expand All @@ -113,22 +130,36 @@ public function onBeforeDisplayProductListView($view, &$productlist)
$product_info[$product->product_id]['quantity'] = $product->product_quantity;
}
if($this->params->get('category_view_show_product_old_price',1) == 1){
$product_info[$product->product_id]['old_price'] = formatprice($product->product_old_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info[$product->product_id]['old_price'] = formatprice($product->product_old_price);
} else {
$product_info[$product->product_id]['old_price'] = \JSHelper::formatprice($product->product_old_price);
}
}

if($this->params->get('category_view_show_product_price',1) == 1 && $this->params->get('category_view_show_product_zero_price',0) == 1){
$product_info[$product->product_id]['price'] = formatprice($product->product_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info[$product->product_id]['price'] = formatprice($product->product_price);
} else {
$product_info[$product->product_id]['price'] = \JSHelper::formatprice($product->product_price);
}
}

if($this->params->get('category_view_show_product_min_price',1) == 1){
$product_info[$product->product_id]['min_price'] = formatprice($product->min_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info[$product->product_id]['min_price'] = formatprice($product->min_price);
} else {
$product_info[$product->product_id]['min_price'] = \JSHelper::formatprice($product->min_price);
}
}
if($this->params->get('category_view_show_product_delivery_time',1) == 1){
$product_info[$product->product_id]['delivery_time'] = $product->delivery_time;
}
}
$doc = Factory::getDocument();
$doc->addScriptOptions('jshop_products_details',$product_info);
Factory::getDocument()->addScriptOptions('jshop_products_details',$product_info);
}//if $productlist->products > 0
}

Expand All @@ -140,6 +171,7 @@ public function onBeforeDisplayProductListView($view, &$productlist)
* @since 1.0.1
*/
public function onBeforeDisplaywtjshoppingfavoritesView($view){
$jversion = new Version();
$product_info = array();
if(count((array)$view->rows) > 0){
foreach($view->rows as $product){
Expand All @@ -160,22 +192,36 @@ public function onBeforeDisplaywtjshoppingfavoritesView($view){
$product_info[$product->product_id]['quantity'] = $product->product_quantity;
}
if($this->params->get('category_view_show_product_old_price',1) == 1){
$product_info[$product->product_id]['old_price'] = formatprice($product->product_old_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info[$product->product_id]['old_price'] = formatprice($product->product_old_price);
} else {
$product_info[$product->product_id]['old_price'] = \JSHelper::formatprice($product->product_old_price);
}
}

if($this->params->get('category_view_show_product_price',1) == 1 && $this->params->get('category_view_show_product_zero_price',0) == 1){
$product_info[$product->product_id]['price'] = formatprice($product->product_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info[$product->product_id]['price'] = formatprice($product->product_price);
} else {
$product_info[$product->product_id]['price'] = \JSHelper::formatprice($product->product_price);
}
}

if($this->params->get('category_view_show_product_min_price',1) == 1){
$product_info[$product->product_id]['min_price'] = formatprice($product->min_price);
if (version_compare($jversion->getShortVersion(), '4.0', '<'))
{
$product_info[$product->product_id]['min_price'] = formatprice($product->min_price);
} else {
$product_info[$product->product_id]['min_price'] = \JSHelper::formatprice($product->min_price);
}
}
if($this->params->get('category_view_show_product_delivery_time',1) == 1){
$product_info[$product->product_id]['delivery_time'] = $product->delivery_time;
}
}
$doc = Factory::getDocument();
$doc->addScriptOptions('jshop_products_details',$product_info);
Factory::getDocument()->addScriptOptions('jshop_products_details',$product_info);
}

}
Expand Down

0 comments on commit b36045a

Please sign in to comment.