0

i have two shipping methods

1)Custom shipping
2)Free shipping

when i select custom shipping it works fine

when i choose free shipping

showing error on checkout

undefined index : pickupStoreVal /checkoutobserver.php on line 70

checkoutobservershipping.php

namespace Mageants\StorePickup\Observer;

use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;

class SaveStorePickupToOrderObserver implements ObserverInterface
{
    /**
     * @var \Magento\Framework\ObjectManagerInterface
     */
    protected $_objectManager;
    /**
     * Store Collection
     *
     * @var \Mageants\StoreLocator\Model\ManageStore
     */
    protected $_storeCollection;


    /**
     * @param \Magento\Framework\ObjectManagerInterface $objectmanager
     */
    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectmanager,
        \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformation,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Mageants\StoreLocator\Model\ManageStore $storeCollection
        )
    {
        $this->_storeCollection = $storeCollection;
        $this->_objectManager = $objectmanager;
        $this->countryInformation = $countryInformation;
        $this->scopeConfig = $scopeConfig;
    }

    public function execute(EventObserver $observer)
    {
        $order = $observer->getOrder();
        $quoteRepository = $this->_objectManager->create('Magento\Quote\Model\QuoteRepository');
        $quote = $quoteRepository->get($order->getQuoteId());
        $order->setPickupDate($quote->getPickupDate());
        $order->setPickupStore($quote->getPickupStore());
        $collection = '';
        $store = '';





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





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


          foreach ($collection->getData() as $stores) 
        {
            $store = $stores;
        }
        if ($order->getShippingMethod() == "storepickup_storepickup") 
        {
            $storeName = explode(' ', $store['sname']);
            $streetAddress = array($store['address']);
            $firstName = '';
            $lastName = '';

            if (count($storeName) == 1) 
            {
                $firstName = "Store";
                $lastName = $storeName[0];
            }
            elseif (count($storeName) > 2) 
            {
                $firstName = $storeName[0];
                for ($i=1; $i < count($storeName); $i++) 
                { 
                    $lastName = $lastName." ".$storeName[$i];
                }
            }
            else{
                $firstName = $storeName[0];
                $lastName = $storeName[1];
            }

            $order->getShippingAddress()->setFirstname($firstName);
            $order->getShippingAddress()->setLastname($lastName);
            $order->getShippingAddress()->setStreet($streetAddress);
            $order->getShippingAddress()->setCity($store['city']);
            $order->getShippingAddress()->setPostcode(trim($store['postcode']));
            $order->getShippingAddress()->setRegion(trim($store['region']));
            $order->getShippingAddress()->setCountryId(strtoupper(trim($store['country'])));
            $order->getShippingAddress()->setTelephone(trim($store['phone']));
            $order->getShippingAddress()->setCompany('');
        }
        return $this;
    }
}

how i can solve this???

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.