0

on the update of quote item price, I am not able to get payment method on payment step in Magento2. It is showing No Payment Methods. Below is my code on beforeSaveAddressInformation for the plugin.

$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
$item->getProduct()->setIsSuperMode(true);
$item->save();

public function beforeSaveAddressInformation(
    \Magento\Checkout\Model\ShippingInformationManagement $subject,
    $cartId,
    \Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
) {
    $postcode = $addressInformation->getShippingAddress()->getPostcode();       
    $zipcodeData = $this->location_pricing->getCollection()->addFieldToFilter('post_code',$postcode)->addFieldToFilter('flag',1)->getFirstItem();


    // $cart = $this->quoteRepository->get($cartId);;
    $cart = $this->cart->getQuote();
    $quotePincode = $cart->getPincode();

    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/cityprice.log');
    $logger = new \Zend\Log\Logger();
    $logger->addWriter($writer);

    if($quotePincode != $postcode){
        $items = $cart->getAllVisibleItems();
        $result = [];
        $product = $this->productFactory->create();
        $cart->setPincode($postcode);
        $cart->setPincodeCity($zipcodeData->getCity());
        if (count($items) > 0){
            foreach ($items as $item){
                $_product = $product->loadByAttribute('sku',$item->getSku());
                $result[] = $item->getSku();
                $cityCollection = $this->pricing->getCollection()->addFieldTofilter('city',$zipcodeData->getCity())
                ->addFieldToFilter('sku',$item->getSku())
                ->getFirstItem()->getData();

                if(!empty($cityCollection)){
                    if($cityCollection['location_special_pricing'] > $cityCollection['location_price'] )
                        $price = $cityCollection['location_price'];
                    else
                        $price = $cityCollection['location_special_pricing'];

                    $item->setCustomPrice($price);
                    $item->setOriginalCustomPrice($price);
                    $item->getProduct()->setIsSuperMode(true);
                    $item->save();
                }
                else{
                    if(($_product->getData('special_price') > 0) && ($_product->getData('special_price') < $_product->getData('price')))
                        $price = $_product->getData('special_price');
                    else
                        $price = $_product->getData('price');

                    $item->setCustomPrice($price);
                    $item->setOriginalCustomPrice($price);
                    $item->getProduct()->setIsSuperMode(true);
                    $item->save();
                }     
            }
            $this->quoteRepository->save($cart);
            $cart->save();
        }
    }
}

My di.xml is below

<type name="Magento\Checkout\Model\ShippingInformationManagement">
    <plugin name="sr_save_delivery_date_in_quote" type="Vendor\Module\Plugin\Checkout\Model\ShippingInformationManagement" sortOrder="1"/>
</type>
  • show your complete code of plugin method. – Dhiren Vasoya May 16 '18 at 12:14
  • I have added my code in my question – Rahul Hedaoo May 17 '18 at 10:32
  • Have you check code by putting it with try.....catch block? – Dhiren Vasoya May 17 '18 at 11:09
  • I have added try and catch block nothing was in exception. – Rahul Hedaoo May 17 '18 at 11:17
  • are you sure, if you remove your price change code then every thing working fine? – Dhiren Vasoya May 17 '18 at 11:20

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.