Posts

Showing posts from March, 2020

How to add product attribute value in minicart magento 2

How to add product attribute value in minicart magento 2? First need to do is create a plugin so add plugin at di.xml at first. di.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Checkout\CustomerData\DefaultItem"> <plugin disabled="false" name="AddAttPlug" sortorder="10" type="Your\Module\Plugin\DefaultItem"> </plugin></type> </config> Now create a plugin class and below line of code.   Default.php <?php namespace Your\Module\Plugin; use Magento\Quote\Model\Quote\Item; class DefaultItem { public function aroundGetItemData($subject, \Closure $proceed, Item $item) { $data = $proceed($item); $product = $item->getProduct(); $atts = [ "product_weight" => $product->ge

How to create a order from quote?

How to create a order from quote in magento 2? Find full answer below. We will load one product than we will create a quote for it and than we will convert that quote into an order. <?php use Magento\Framework\App\Action\Action; class OrderCreateTest extends Action {     protected $_quoteFactory;     protected $_orderModel;     protected $_productModel;     protected $_customerRepository;     protected $_quoteManagementModel;          public function __construct(\Magento\Quote\Model\QuoteFactory $quoteFactory, \Magento\Sales\Model\Order $orderModel, \Magento\Catalog\Model\Product $productModel, \Magento\Framework\App\Action\Context $context, \Magento\Quote\Model\QuoteManagement $quoteManagementModel, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository)     {         $this->_quoteFactory         = $quoteFactory;         $this->_orderModel           = $orderModel;         $this->_productModel         = $productModel;