【问题标题】:Magento: Display custom product price in product listing, view page and also set same price after adding product to cartMagento:在产品列表中显示自定义产品价格,查看页面并在将产品添加到购物车后设置相同的价格
【发布时间】:2014-10-10 10:16:13
【问题描述】:

我需要为每种产品显示自定义价格,管理员将为每种产品设置不同的价格。并且该产品价格只应显示在产品列表和产品查看页面中,不改变产品实际价格。同样的价格也应该适用于购物车。我尝试使用 catalog_product_get_final_price 观察者,但它将价格显示为特价但不会改变产品价格的显示。请给我一个想法,我该怎么做?在此先感谢:)

【问题讨论】:

    标签: magento


    【解决方案1】:
    on list page and view page just check whether your custom price is null nor not if it is null show original price and if it not null show custom price.
    
    create a event in config file **checkout_cart_product_add_after** as given below
    
    <events>
        <checkout_cart_product_add_after>
              <observers>
                    <unique_event_name>
                      <class>modulename/observer</class>
                      <method>modifyPrice</method>
                      </unique_event_name>
                </observers>
          </checkout_cart_product_add_after>
    </events>
    
    
    create new file **Observer.php**
    
    
        class namespace_modulename_Model_Observer
    
          {
    
              public function modifyPrice(Varien_Event_Observer $obs)
                 {
                     // Get the quote item
    
                     $item = $obs->getQuoteItem();
    
                     // Ensure we have the parent item, if it has one
    
                     $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
    
                     // Load the custom price
    
                     $price = $this->_getPriceByItem($item);
    
                     // Set the custom price
    
                     $item->setCustomPrice($price);
    
                     $item->setOriginalCustomPrice($price);
    
                     // Enable super mode on the product.
    
                     $item->getProduct()->setIsSuperMode(true);
    
                 }
    
    
                 protected function _getPriceByItem(Mage_Sales_Model_Quote_Item $item)
                 {
                     $price;
    
                     //use $item to determine your custom price.
    
                     return $price;
                 }
                    }
    

    【讨论】:

    • 是的,这是个好主意。但是对于可配置和捆绑产品,在选择自定义选项时,它会在产品视图页面中显示默认价格。如何在选择自定义选项时设置自定义价格。
    • 在产品添加到购物车事件中,您将获得产品的 ID,您可以从该产品 ID 加载该产品的价格
    • 没错,我们可以获取产品id,并为购物车设置自定义价格。但是,我的问题是关于选择选项,价格会在产品视图页面上使用 js 功能改变。在我的情况下,即使选择了不同的选项,价格也没有改变。无论如何,我现在解决了这个问题。感谢大家的想法和建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 2012-04-01
    相关资源
    最近更新 更多