我一直在尝试在购物车中覆盖Carchout的Card Controller中的getbackull方法。偏好我在没有问题的情况下管理,但插件有点挑战。

这是我到目前为止的内容。

di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Controller\Cart\Add">
        <plugin name="[namespace]_[module]_checkout_controller_cart_add_before" type="[Namespace]\[Module]\Controller\Checkout\Cart\Plugin" sortOrder="1" />
    </type>
</config>
.

Controller/Checkout/Cart/Plugin.php

namespace [Namespace]\[Module]\Controller\Checkout\Cart;

class Plugin
{

    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $_config;

    /**
     * @var \Magento\Framework\Url
     */
    protected $_url;

    /**
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
     * @param \Magento\Framework\Url $url
     */
    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $config,
        \Magento\Framework\Url $url
    ) {
        $this->_config = $config;
        $this->_url = $url;
    }

    /**
     * Get resolved back url, rewritten to return checkout URL instead of cart url
     *
     * @param \Magento\Checkout\Controller\Cart\Add $subject
     * @return string
     */
    protected function beforeGetBackUrl(\Magento\Checkout\Controller\Cart\Add $subject)
    {
        return $this->_url->getUrl('some/custom/url');
    }
}
.

无论我尝试什么,我都无法让它到达beforeGetBackUrl方法。

有帮助吗?

其他提示

你不能将getbackul插件,但你可以geturl。

为此,您需要:

  1. 从\ magento \ framework \ url
  2. 创建虚拟类型myurlbulder
  3. 使用它作为\ magento \ checkout \ controller \ cart \ add
  4. 的参数
  5. 为myurlbulder虚拟类型
  6. 声明插件
许可以下: CC-BY-SA归因
scroll top