每当您在 Magento 中加载购物车页面时,都会运行以下代码
$cart->init();
$cart->save();
这样做的一个副作用是,如果产品价格已更新,则购物车中任何商品的价格都会更新。这实际上更新了 sales_flat_quote_item
中的条目。我正在尝试追踪每个报价项目的价格在代码的位置更新,以及每个报价项目的保存位置。
我知道它可以设置的无数位置。我希望有人知道它的实际设置位置。专门针对 Magento 1.7x 分支,尽管欢迎来自所有版本的信息。
最佳答案
这个是我自己挖的。所以有这个
#File: app/code/core/Mage/Sales/Model/Quote.php
foreach ($this->getAllAddresses() as $address) {
...
$address->collectTotals();
...
}
这导致了这个
#File: app/code/core/Mage/Sales/Model/Quote/Address.php
public function collectTotals()
{
Mage::dispatchEvent($this->_eventPrefix . '_collect_totals_before', array($this->_eventObject => $this));
foreach ($this->getTotalCollector()->getCollectors() as $model) {
$model->collect($this);
}
Mage::dispatchEvent($this->_eventPrefix . '_collect_totals_after', array($this->_eventObject => $this));
return $this;
}
getTotalCollector
对象返回一个sales/quote_address_total_collector
对象,该对象从global/sales/quote/totals
加载一系列收集器模型并对它们调用 collect
。小计收集器的collect
方法最终调用这个
#File: app/code/core/Mage/Sales/Model/Quote/Address/Total/Subtotal.php
protected function _initItem($address, $item)
{
//...
if ($quoteItem->getParentItem() && $quoteItem->isChildrenCalculated()) {
$finalPrice = $quoteItem->getParentItem()->getProduct()->getPriceModel()->getChildFinalPrice(
$quoteItem->getParentItem()->getProduct(),
$quoteItem->getParentItem()->getQty(),
$quoteItem->getProduct(),
$quoteItem->getQty()
);
$item->setPrice($finalPrice)
->setBaseOriginalPrice($finalPrice);
$item->calcRowTotal();
} else if (!$quoteItem->getParentItem()) {
$finalPrice = $product->getFinalPrice($quoteItem->getQty());
$item->setPrice($finalPrice)
->setBaseOriginalPrice($finalPrice);
$item->calcRowTotal();
$this->_addAmount($item->getRowTotal());
$this->_addBaseAmount($item->getBaseRowTotal());
$address->setTotalQty($address->getTotalQty() + $item->getQty());
}
//...
}
这是报价项目获得其价格设置/休息的地方。
关于php - Magento 在哪里设置报价项目的价格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11548659/