如何通过Magento中的观察员设置运费折扣?

问题描述

我在事件'sales_quote_collect_totals_before'下创建了一个观察员,我想增加运费折扣。

public function execute(Observer $observer)
    {

            $companyId  = $this->companyUser->getCurrentCompanyId();
            $company    = $this->companyRepository->get($companyId);

        if (!$company->getUseAllowanceForShipping()) {
            $quote = $observer->getQuote();
            $total = $observer->getData('total');
            $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
            $address->setShippingAmount(0);
            $address->collectShippingRates();
             $total->setShippingdiscountAmount($address->getShippingInclTax());
        }
}

这是我到目前为止所拥有的,但是没有运气。

enter image description here

我还可以添加一个折扣名称,例如Paid by Company吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)