1

I have added two shipping options and getting price in estimated shipping section in cart page. but when I select one shipping option then it is selecting both option. I need one selection at a time as default work. please check attech screenshot:

enter image description here

Please find my code where I am calling both shipping options in

/app/code/Mageplaza/MyModule/Model/Carrier/Carrier.php

 public function collectRates(RateRequest $request)
{
    if (!$this->getConfigFlag('active')) {
        return false;
    }

     $shippingPrice = 0;
     $premiumshipPrice = $shippingPrice+15;

     $shippingPrice=(float)$shippingPrice;
     $result = $this->_rateResultFactory->create();
    $methodship= array( "Standard Shipping", "Premium Shipping");
    foreach($methodship as $mship) {  
            if($mship == "Premium Shipping")
            {
            $method = $this->_rateMethodFactory->create();
            $method->setCarrier($this->_code);
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethod($this->_code);
            $method->setMethodTitle($mship);
            $method->setPrice($premiumshipPrice);
            $method->setCost($premiumshipPrice);
            $result->append($method);
            }else{

            $method = $this->_rateMethodFactory->create();
            $method->setCarrier($this->_code);
            $method->setCarrierTitle($this->getConfigData('title'));
            $method->setMethod($this->_code);
            $method->setMethodTitle($mship);
            $method->setPrice($shippingPrice);
            $method->setCost($shippingPrice);
            $result->append($method);
            }
            }
                return $result;
        }

please let me know If I am missing something here, Kindly help me for this.

  • maybe try to use === instead of == – magefms Feb 15 at 4:27
  • like this if($mship === "Premium Shipping") – magefms Feb 15 at 4:27
  • which shipping is in your $_code ? – magefms Feb 15 at 4:31
  • @magefms I have tried with === but still getting both option selection. Can you please check again. – Ravi Varma Feb 15 at 4:32
  • please post your $_code value – magefms Feb 15 at 4:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.