Created
June 3, 2024 19:50
-
-
Save CB9TOIIIA/651e18abbc1f584ab57c506190486cea to your computer and use it in GitHub Desktop.
Пример плагина для Radicalmart на событие onRadicalMartImportBeforeTargetSave
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
XML файл: rmestetscent.xml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<extension type="plugin" group="radicalmart_import" method="upgrade"> | |
<name>RM Estetscent settings</name> | |
<version>1.0.0</version> | |
<description>RM Estetscent plugin for RadicalMart import</description> | |
<files> | |
<filename plugin="rmestetscent">rmestetscent.php</filename> | |
</files> | |
<config> | |
<fields name="params"> | |
<fieldset name="basic"> | |
<field name="price_limit_1" type="number" default="110" label="Price Limit 1" description="The first price limit for determining the extra amount"/> | |
<field name="price_limit_2" type="number" default="220" label="Price Limit 2" description="The second price limit for determining the extra amount"/> | |
<field name="extra_1" type="number" default="15" label="Extra Amount 1" description="The extra amount added when price is below or equal to Price Limit 1"/> | |
<field name="extra_2" type="number" default="25" label="Extra Amount 2" description="The extra amount added when price is between Price Limit 1 and Price Limit 2"/> | |
<field name="extra_3" type="number" default="30" label="Extra Amount 3" description="The extra amount added when price is above Price Limit 2"/> | |
</fieldset> | |
</fields> | |
</config> | |
</extension> | |
PHP файл: rmestetscent.php | |
<?php | |
defined('_JEXEC') or die; | |
use Joomla\CMS\Plugin\CMSPlugin; | |
class PlgRadicalmart_importRmestetscent extends CMSPlugin | |
{ | |
protected $app; | |
public function onRadicalMartImportBeforeTargetSave($target, $params, &$item) | |
{ | |
// Установить 'purchase_enable' в '1' | |
$item->set('prices.usd.purchase_enable', '1'); | |
// Получить значение 'purchase' в USD | |
$price = (int) $item->get('prices.usd.purchase'); | |
// Получить лимиты и значения extra из параметров плагина | |
$priceLimit1 = $this->params->get('price_limit_1', 110); | |
$priceLimit2 = $this->params->get('price_limit_2', 220); | |
$extra1 = $this->params->get('extra_1', 15); | |
$extra2 = $this->params->get('extra_2', 25); | |
$extra3 = $this->params->get('extra_3', 30); | |
// Определить значение 'extra' | |
$extra = 0; | |
if ($price <= $priceLimit1) { | |
$extra = $extra1; | |
} elseif ($price > $priceLimit1 && $price <= $priceLimit2) { | |
$extra = $extra2; | |
} else { | |
$extra = $extra3; | |
} | |
// Установить значение 'extra' в USD | |
$item->set('prices.usd.extra', $extra); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment