У меня проблема при редактировании заказа в бэкэнде Magento. В начале у меня есть пользовательская цена, когда добавить продукт в корзину. Цена в бэк-энде хорошая (показывать и корректировать в порядке), но когда я нажимаю изменить ордер, цена не корректна в Item
порядок. Я видел, как получить цену по умолчанию продукта. Я пытаюсь поймать событие sales_quote_save_before и попробовать код
$quote = $observer->getEvent()->getQuote();
foreach ($quote->getAllItems() as $item)
{
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
}
но я устанавливаю только индивидуальную цену для каждого элемента в заказе, я не могу установить Промежуточный итог и строку Промежуточный итог для заказа. не могли бы вы сказать мне, как это сделать? Большое спасибо
Вы можете программно установить промежуточные итоги и другие связанные атрибуты следующим образом:
$order = Mage::getModel('sales/order')->setIncrementId($reservedOrderId)->setStoreId($storeId); // if saving new one
$order = Mage::getModel('sales/order')->loadByIncrementId('10012345'); //if loading product
$order->setSubtotal($sub_total)
$order->setBaseSubtotal($base_sub_total)
$order->setTaxAmount($some_tax_price)
$order->setGrandTotal($grand_total)
$order->setBaseGrandTotal($base_grand_total);
Обратите внимание, что если вы вносите изменения таким образом, то некоторые отчеты могут неправильно рассчитывать порядок (ы) (например, панель инструментов)
Можете попробовать следующее решение —
Можно создать решение с помощью модуля Magento
1)
config.xml, нужно добавить блок с событием sales_convert_order_item_to_quote_item — лайк
<adminhtml>
<events>
<sales_convert_order_item_to_quote_item>
<observers>
<orderpricesfromoldorder_old_prices>
<type>singleton</type>
<class>Magefast_OrderPricesFromOldOrder_Model_Observer</class>
<method>salesEventOrderItemToQuoteItemPrices</method>
</orderpricesfromoldorder_old_prices>
</observers>
</sales_convert_order_item_to_quote_item>
</events>
</adminhtml>
2) Файл наблюдателя с функцией / методом — как
public function salesEventOrderItemToQuoteItemPrices($observer)
{
/** @var $orderItem Mage_Sales_Model_Order_Item */
$orderItem = $observer->getEvent()->getOrderItem();
$quoteItem = $observer->getEvent()->getQuoteItem();
// Do not import giftmessage data if order is reordered
$order = $orderItem->getOrder();
if ($order && $order->getReordered()) {
return $this;
}
// mage::log($orderItem->getData('price'));
// mage::log($quoteItem->getProduct()->getData('price'));
if ($orderItem->getData('price') && $orderItem->getData('price') != '') {
$quoteItem->setCustomPrice($orderItem->getData('price'));
$quoteItem->setOriginalCustomPrice($orderItem->getData('price'));
}
return $this;
}
Вы можете проверить модуль Magento Core — Mage_GiftMessage
Итак, когда отредактируете Order через Adminpanel — цены будут такими же.
но будьте осторожны с низкими ценами 🙂
Добавив решение Magefast, я обнаружил, что вам также необходимо setCustomPrice()
на родительский элемент при работе с настраиваемыми продуктами. Предложение будет содержать как простой, так и настраиваемый продукт, вы хотите, чтобы обе строки обновлялись по индивидуальной цене.
Метод наблюдателя:
public function setCustomPriceForItem($observer)
{
$quoteItem = $observer->getQuoteItem();
$orderItem = $observer->getOrderItem();
$session = Mage::getSingleton('customer/session');
if ($session != null && !$session->getReordered() && $orderItem->getOriginalPrice() != $orderItem->getPrice()) {
$quoteItem->setCustomPrice($orderItem->getPrice());
$quoteItem->setOriginalCustomPrice($orderItem->getPrice());
//also update the price on the parent item
if ($parentQuoteItem = $quoteItem->getParentItem()) {
$parentQuoteItem->setCustomPrice($orderItem->getPrice());
$parentQuoteItem->setOriginalCustomPrice($orderItem->getPrice());
}
}
return $this;
}