php - Magento 在哪里设置报价项目的价格?

标签 php oop magento

每当您在 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/

相关文章:

php - Laravel 通过关系搜索

php - PHP 中的异常真的那么有用吗?

magento - 如何以编程方式设置Magento存储配置数据?

多个多语言网站的 Magento 产品翻译

php - 函数 get_permalink() 在 if 语句中不能正常工作 (Wordpress)

php - 使用 phpMyAdmin for xcode 从 MySQL 获取数据

php - 执行更多或更复杂的 SQL 查询,或使用 PHP 过滤数据?

oop - 理解 OOP 中的抽象

c# - 从类(class)内部访问类(class)成员

magento - Magento 2中的Ultimo控制台错误