get('Mageplaza\cart\block\getitems'); $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $messageManager = $objectManager->get('\Magento\Framework\Message\ManagerInterface'); $productRepo = $objectManager->get('\Magento\Catalog\Model\ProductRepository'); $productPar = $objectManager->get('\Magento\Catalog\Model\Product'); $imageFactory = $objectManager->get('\Magento\Catalog\Helper\ImageFactory'); $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); $cartHelper = $objectManager->get('\Magento\Checkout\Helper\Cart'); $formKey = $objectManager->get('\Magento\Framework\Data\Form\FormKey'); $listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct'); if (isset($_POST['submit'])){ $params = array(); $params = array( 'form_key' => $formKey->getFormKey(), 'product' => $_POST['pid'], 'qty' => $_POST['qty'] ); $cart = $objectManager->create('\Magento\Checkout\Model\Cart'); $productId = $_POST['pid']; $customPrice = '9.99'; //$product = $productPar->load($productId); $product = $productRepo->getById($productId); $product->setCustomPrice($customPrice); // without save this does the trick $product->getProduct()->setIsSuperMode(true); $cart->addProduct($product, $params); $cart->save(); } ?>

Paid Advertisement

© 2019 The Factory Furnace Outlet