0

Is it possible that we can change product type in quote. We dont want to change product type in database but only for specific quote. When user add any configurable product to cart then based on some conditions (we will define them in event) we will flip product type from configurable physical to virtual.

  • I think it can be done, as far as i remember quote and quote_item have is_virtual field in case quote has virtual products. Try to set this field as true in both tables. – Ramkishan Suthar Jan 22 at 17:43
0

You need to create Observer to update product type. If you have created module then Mageseller/UpdateProduct/etc/event.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="checkout_cart_product_add_after">
        <observer name="custom_update_product_type" instance="Mageseller\UpdateProduct\Observer\UpdateProductType" />
    </event>
</config>

Now create below file Mageseller/UpdateProduct/Observer/UpdateProductType.php in Observer folder.

<?php
    namespace Mageseller\UpdateProduct\Observer;

    use Magento\Framework\Event\ObserverInterface;
    use Magento\Framework\App\RequestInterface;

    class UpdateProductType implements ObserverInterface
    {
        public function execute(\Magento\Framework\Event\Observer $observer) {
            $item = $observer->getEvent()->getData('quote_item');         
            $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
            $productType = 'virtual'; //set your price here
            // condition starts
            $item->setProductType($productType);
            $item->getProduct()->setIsSuperMode(true);
            // condition ends
        }

    }

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.