Я использую наблюдатель с событием sales_quote_item_qty_set_after, чтобы гарантировать, что цена запускается каждый раз, когда продукт перенастраивается, поскольку мне не удалось получить желаемые результаты от других событий.
Проблема, с которой я столкнулся, заключается в невозможности изменить цену продукта в предложении при циклическом просмотре предложения с помощью ->getAllItems().
Я знаю, что цену можно переопределить с помощью следующих событий для событий добавления продукта.
Код: Выделить всё
$_item = $obs->getQuoteItem();
$_item = ( $_item->getParentItem() ? $_item->getParentItem() : $_item );
$new_price = 1000;
$_item->setCustomPrice($new_price);
$_item->setOriginalCustomPrice($new_price);
$_item->getProduct()->setIsSuperMode(true);
Полный код приведен ниже...
Код: Выделить всё
public function adminAddProduct(Varien_Event_Observer $obs) {
$quote = $this->_getSession()->getQuote();
foreach($quote->getAllItems() as $_item){
$options = $_item->getProduct()->getTypeInstance(true)->getOrderOptions($_item->getProduct());
$_product = $_item->getProduct();
$sku = $options['simple_sku'];
if ($sku) {
$tierPrices = $_product->getTierPrice();
$price = $_item->getPrice();
$qty = $options['info_buyRequest']['qty'];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$sku);
$runspeed = $product->getResource()->getAttribute('runspeed')->getFrontend()->getValue($product);
$prodOpts = [];
foreach($options['options'] as $option) {
$prodOpts[$option['label']] = $option['value'];
}
$index = 0;
foreach($tierPrices as $tierPrice) {
if($tierPrice['price_qty'] $qty) {
$price = $tierPrice['price'];
}
//$prodTiers[$tierPrice['price_qty']] = $tierPrice['price'];
}
if($prodOpts['Quantity'] == 'Fixed Quantity' && array_key_exists('Quantity Select', $prodOpts)){
$qty = str_replace(',', '', explode(" ", $prodOpts['Quantity Select'])[0]);
} else {
$qty = 1;
}
$_item->setQty($qty);
$_item->setCustomPrice($customPrice)->setOriginalCustomPrice($customPrice);
$new_price = 999;
$_item->setPrice($new_price);
$_item->setCustomPrice($new_price);
$_item->setOriginalCustomPrice($new_price);
$_item->save();
Mage::log($price);
Mage::log($prodOpts);
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/373 ... quote-loop