Влад Цепеш Posted February 14, 2025 Posted February 14, 2025 /home/TestUser/web/сайт/public_html/myshop/vendor/aimeos/ai-client-html/templates/client/html/common/partials/price.php Здесь находится вывод цен Один из способов решить вопрос ценообразования - создать новые правила ценообразования. Для этого нужно создать нового провайдера в этой директории /home/TestUser/web/сайт/public_html/myshop/vendor/aimeos/aimeos-core/src/MShop/Rule/Provider/Catalog/ Необходимо наличие данных строк кода namespace Aimeos\MShop\Rule\Provider\Catalog; class Myprovider extends \Aimeos\MShop\Rule\Provider\Base implements \Aimeos\MShop\Rule\Provider\Catalog\Iface, \Aimeos\MShop\Rule\Provider\Factory\Iface { public function apply( \Aimeos\MShop\Product\Item\Iface $product ) : bool { return $this->isLast(); } } А так же стоит добавить конфигурацию правил public function apply( \Aimeos\MShop\Product\Item\Iface $product ) : bool { //То что было написано ранее } private $beConfig = [ 'myprovider.minprice' => [ 'code' => 'myprovider.minprice', 'internalcode' => 'myprovider.minprice', 'label' => 'Minimum price', 'type' => 'number', 'internaltype' => 'string', 'default '=> '0', 'required' => true, ], ]; public function checkConfigBE( array $attributes ) : array { $errors = parent::checkConfigBE( $attributes ); return array_merge( $errors, $this->checkConfig( $this->beConfig, $attributes ) ); } public function getConfigBE() : array { return array_merge( parent::getConfigBE(), $this->getConfigItems( $this->beConfig ) ); } В результате получился провайдер с таким кодом <?php namespace Aimeos\MShop\Rule\Provider\Catalog; class PriceServiceProvider extends \Aimeos\MShop\Rule\Provider\Base implements \Aimeos\MShop\Rule\Provider\Catalog\Iface, \Aimeos\MShop\Rule\Provider\Factory\Iface { public function apply( \Aimeos\MShop\Product\Item\Iface $product ) : bool { //Пример с уменьшением цен на 10 процентов foreach( $product->getRefItems( 'price' ) as $price ) { $value = $price->getValue(); $discount = $value * 10 / 100; $price->setValue( $value - $discount )->setRebate( $discount ); } $min = $this->getConfigValue( 'priceserviceprovider.minprice', 0 ); //return $product->getPrice()->getValue() > $min ? true : false; return $this->isLast(); } private $beConfig = [ 'priceserviceprovider.minprice' => [ 'code' => 'priceserviceprovider.minprice', 'internalcode' => 'priceserviceprovider.minprice', 'label' => 'Minimum price', 'type' => 'number', 'internaltype' => 'string', 'default '=> '0', 'required' => true, ], ]; public function checkConfigBE( array $attributes ) : array { $errors = parent::checkConfigBE( $attributes ); return array_merge( $errors, $this->checkConfig( $this->beConfig, $attributes ) ); } public function getConfigBE() : array { return array_merge( parent::getConfigBE(), $this->getConfigItems( $this->beConfig ) ); } } При добавлении в админке этого правила, проблем не возникло. После создания оно сразу начинает работать
Влад Цепеш Posted February 17, 2025 Author Posted February 17, 2025 Осталось только сделать изменение относительно главной валюты. Здесь получилось реализовать изменение цены путём проверки id выставленной пользователем валюты Собственно, если указан не Юань, то к цене добавляется 55
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now