Skip to content

Instantly share code, notes, and snippets.

@madcatgith
Created August 9, 2019 19:14
Show Gist options
  • Save madcatgith/5458696e12a8eae00ac4579136d93eeb to your computer and use it in GitHub Desktop.
Save madcatgith/5458696e12a8eae00ac4579136d93eeb to your computer and use it in GitHub Desktop.
[BITRIX] Подмена родительского класса компонента ядра
<?php
include_once('../../../../bitrix/components/bitrix/sale.order.ajax/class.php');
use \Bitrix\Sale\Order;
use \Bitrix\Sale\BasketBase;
/**
* Подмена родительского класса компонента ядра
* в данном частном случае размещается в файле local/components/bitrix/sale.order.ajax/class.php
*
* @author Vladimir Tikunov <vtikunov@yandex.ru>
*/
class SaleOrderAjaxLaptop extends SaleOrderAjax
{
private $isChangePersonType = false;
protected function initPersonType(Order $order)
{
$result = parent::initPersonType($order);
$this->isChangePersonType = !!$result;
return $result;
}
protected function initBasket(Order $order)
{
parent::initBasket($order);
if (!$this->isChangePersonType) {
return;
}
$basket = $order->getBasket();
if (!$basket instanceof BasketBase) {
return;
}
foreach ($basket->getIterator() as $item) {
$isCustomPrice = $item->getField('CUSTOM_PRICE') === 'Y';
if ($isCustomPrice) {
$productId = $item->getProductId();
$item->setPrice('ЗДЕСЬ НАДО ЦЕНУ ПО ID');
$item->setField('CUSTOM_PRICE', 'N');
continue;
}
$currentPrice = $item->getPrice();
$item->setPrice('ЗДЕСЬ НАДО ФОРМУЛУ');
$item->setField('CUSTOM_PRICE', 'Y');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment