문제

I want to delete the coupon code programmatically. My code is:

$cart = $this->quoteRepository->getActive($cartId);

  if(isset($response_json['errorMessage']) || $json_response['status']['statusCode'] == 0){
    $cart->setCouponCode('');
    $cart->collectTotals()->save();
    $this->logger->debug("test");
  }

I see the "test" in my debug. But the Coupon code not removed. Can someone help me?

Thank you in advance!

도움이 되었습니까?

해결책

You can do it like below.

if(isset($response_json['errorMessage']) || $json_response['status']['statusCode'] == 0){
    $cart->setCouponCode('');
    $this->quoteRepository->save($cart->collectTotals());
    $this->logger->debug("test");
}

다른 팁

I suggest another way. Go to your xml file and put this code at before body tag close

<referenceBlock name="block_name" remove="true"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top