Magento2 如何通过Magento中的观察员设置发货折扣?

Magento2 如何通过Magento中的观察员设置发货折扣?,magento2,checkout,Magento2,Checkout,我在“sales\u quote\u collect\u totals\u before”事件下创建了一个观察者,我想添加运费折扣 public function execute(Observer $observer) { $companyId = $this->companyUser->getCurrentCompanyId(); $company = $this->companyRepository->

我在“sales\u quote\u collect\u totals\u 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());
        }
}
这是我到目前为止所拥有的,但运气不好

我还可以添加一个折扣名称,如公司支付的