0

The shipping method custom module's observer shows error

checkoutobservershipping.php

 if ($_COOKIE['pickupStoreVal']) 
        {
            $id = $_COOKIE['pickupStoreVal'];
            $collection = $this->_storeCollection->getCollection()->addFieldToFilter('store_id', $id);
        }

undefined index : pickupStoreVal /checkoutobserver.php on line 54

I have two shipping methods

1)Free shipping

2)Store pickup - custom module

When I select free shipping it will be showing error

I also tried

if (isset($_COOKIE['pickupStoreVal'])) 

How I can resolve this?

  • please add full code – Rk Rathod Apr 3 at 7:45
0
$id = $_COOKIE['pickupStoreVal'] ?? false;
if ($id) 
{
    $collection = $this->_storeCollection->getCollection()->addFieldToFilter('store_id', $id);
}
  • if $_COOKIE['pickupStoreVal'] has value what happen it would won't affect the code – prabhakaran7 Apr 3 at 7:49
  • if it will have value, it will execute the code inside condition, if not, it wont. ?? is just like isset as per php 7+. – Yash Shah Apr 3 at 7:50
  • hooo superb............ – prabhakaran7 Apr 3 at 7:51
  • 1
    this not working bro – prabhakaran7 Apr 3 at 7:56
  • what error it is showing ? – Yash Shah Apr 3 at 8:46
0

You should try using !isset function, check below sample:

if(!isset($_COOKIE['pickupStoreVal'])) {
    $id = $_COOKIE['pickupStoreVal'];
    $collection = $this->_storeCollection->getCollection()->addFieldToFilter('store_id', $id);
} else {
    //your cookie is not set message
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.