Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento:在产品列表、查看页面中显示自定义产品价格,并在将产品添加到购物车后设置相同的价格_Magento - Fatal编程技术网

Magento:在产品列表、查看页面中显示自定义产品价格,并在将产品添加到购物车后设置相同的价格

Magento:在产品列表、查看页面中显示自定义产品价格,并在将产品添加到购物车后设置相同的价格,magento,Magento,我需要显示每个产品的自定义价格,管理员将为每个产品设置不同的价格。并且此产品价格只应显示在产品列表和产品查看页面中,而不更改产品实际价格。同样的价格也适用于购物车。我尝试使用catalog_product_get_final_price observer,但它将价格显示为特殊价格,但不会改变产品价格的显示。请给我一个主意,我怎么做?提前感谢:)在列表页面和查看页面上,只需检查您的自定义价格是否为空,如果为空,则显示原始价格,如果不为空,则显示自定义价格。 在配置文件**签出\购物车\产品\在**

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

在列表页面和查看页面上,只需检查您的自定义价格是否为空,如果为空,则显示原始价格,如果不为空,则显示自定义价格。
在配置文件**签出\购物车\产品\在**后添加\中创建一个事件,如下所示
模名/观察者
修改价格
创建新文件**Observer.php**
类名称空间\u模块名称\u模型\u观察者
{
公共功能修改价格(可变事件观察员$obs)
{
//获取报价项
$item=$obs->getQuoteItem();
//确保我们有父项(如果有)
$item=($item->getParentItem()?$item->getParentItem():$item);
//加载自定义价格
$price=$this->\u getPriceByItem($item);
//设定自定义价格
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
//在产品上启用超级模式。
$item->getProduct()->setIsSuperMode(true);
}
受保护功能\u getPriceByItem(Mage\u Sales\u Model\u Quote\u Item$Item)
{
$price;
//使用$item确定您的自定义价格。
返回$price;
}
}

是的,这是个好主意。但对于可配置和捆绑产品,在选择自定义选项时,它会在产品视图页面中显示默认价格。如何在选择自定义选项时设置自定义价格。在“产品添加到购物车”事件中,您将获得产品的id,您可以从该产品id加载该产品的价格。没错,我们可以获取产品id并为购物车项目设置自定义价格。但是,我的问题是选择选项,价格将使用产品视图页面上的js功能进行更改。在我的例子中,即使选择了不同的选项,价格也没有变化。不管怎样,我现在解决了这个问题。谢谢大家的想法和建议。
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;
             }
                }