【问题标题】:Change the product price after catalog price rules in Magento 2在 Magento 2 中的目录价格规则之后更改产品价格
【发布时间】:2021-02-04 02:33:36
【问题描述】:

在应用所有目录规则后,我需要更改所有页面中的产品价格,用于目录(产品列表)、购物车等的所有操作。我在 frontend/di.xml 上为 Magento\Catalog\Pricing\Price\FinalPrice 创建了一个插件

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Pricing\Price\FinalPrice">
        <plugin name="Pefsa_Redondeo_Plugin_Magento_Catalog_Pricing_Price_FinalPrice" type="Pefsa\Redondeo\Plugin\Magento\Catalog\Pricing\Price\FinalPrice" sortOrder="10" disabled="false"/>
    </type>
</config>

然后我就有了方法

public function afterGetMinimalPrice(
        \Magento\Catalog\Pricing\Price\FinalPrice $subject,
        $result
    ) {
        //Custom code here
        
        return $result;
    }

我只能为产品页面获取 $result 上的值,但我无法更改该值。最重要的是,我需要在其他地方更改它,例如类别页面等等...更改正常价格很容易,就像这种方法https://webkul.com/blog/set-custom-product-price-when-displaying-on-front-end-in-magento-2/#comment-44779 ...但是当应用了目录规则时,情况就不同了。有人可以指出我正确的方向吗?亲切的问候和感谢任何形式的帮助。

【问题讨论】:

    标签: magento magento-2.0


    【解决方案1】:

    朋友们...我发现如果我在插件上使用 afterGetValue() 而不是 afterGetMinimalPrice() 方法,实际值更改,在产品页面和类别页面中......但是当我将产品添加到购物车时不起作用。任何想法都会受到高度赞赏。

    谢谢

    【讨论】:

    • 对于面临相同问题的任何人...为 checkout_cart_product_add_after 事件创建观察者可以在我将产品添加到购物车时更改价格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多