diff --git a/fields/plugininfo.php b/fields/plugininfo.php index 0074915..f8f4d2a 100644 --- a/fields/plugininfo.php +++ b/fields/plugininfo.php @@ -64,7 +64,7 @@ protected function getLabel() ?>
-
+ -
+
v.version; ?>
diff --git a/script.php b/script.php index b416d75..539b490 100644 --- a/script.php +++ b/script.php @@ -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. * @@ -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 = ""; + + } else { + + $element = strtoupper($installer->getElement()); + $class = 'col-'; + $web_tolk_site_icon = ''; + } + + $smile = ''; + if($type != 'uninstall'){ + $smiles = ['☺','😀','😉','😍','😎','😊','🙏']; + $smile_key = array_rand($smiles, 1); + $smile = $smiles[$smile_key]; + } echo " +
+
+

".$smile.Text::_("PLG_".$element."_AFTER_".strtoupper($type))."
".Text::_("PLG_".$element)."

+ ".Text::_("PLG_".$element."_DESC"); -
-
-

".Text::_("PLG_".strtoupper($parent->get("element"))."_AFTER_".strtoupper($type))."
".Text::_("PLG_".strtoupper($parent->get("element")))."

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

Joomla Extensions

-

https://web-tolk.ru info@web-tolk.ru

- ".Text::_("PLG_".strtoupper($parent->get("element"))."_MAYBE_INTERESTING")." +

+ ".$web_tolk_site_icon." https://web-tolk.ru + info@web-tolk.ru +

+

Joomla Russian Community in Telegram

+ ".Text::_("PLG_".$element."_MAYBE_INTERESTING")."
- "; - - } + "; + + } } \ No newline at end of file diff --git a/wt_add_products_info_to_joomla_script_options.php b/wt_add_products_info_to_joomla_script_options.php index b481596..1b6a33f 100644 --- a/wt_add_products_info_to_joomla_script_options.php +++ b/wt_add_products_info_to_joomla_script_options.php @@ -9,6 +9,7 @@ defined('_JEXEC') or die; use Joomla\CMS\Plugin\CMSPlugin; use Joomla\CMS\Factory; +use Joomla\CMS\Version; /* @@ -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') @@ -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; @@ -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; @@ -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){ @@ -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 } @@ -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){ @@ -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); } }