Creating an external script to import Quotes/Cart (other CMS). My code able to add quote but not creating cart. Need all quoted items to show when user login to their account. I have enabled persistent cart also.
class QuoteMove extends MagentoFrameworkAppHttp implements MagentoFrameworkAppInterface
public function __construct(
MagentoFrameworkObjectManagerInterface $objectManager,
MagentoFrameworkEventManager $eventManager,
MagentoFrameworkAppAreaList $areaList,
MagentoFrameworkAppRequestHttp $request,
MagentoFrameworkAppResponseHttp $response,
MagentoFrameworkObjectManagerConfigLoaderInterface $config,
MagentoFrameworkAppState $state,
MagentoFrameworkFilesystem $fileSystem,
MagentoFrameworkRegistry $registry,
MagentoStoreModelStore $store,
PsrLogLoggerInterface $logger,
MagentoFrameworkFileCsv $csvProcessor,
MagentoQuoteModelQuoteFactory $quote,
MagentoCatalogModelProduct $product
)
$quotes = [];
$email = [email protected];
$qty = xxx ;
$customerId = xxx ;
$this->customer = $this->getCustomerByEmail($email);
$customerId = $this->customer->getId();
$quote = $this->quotes[$customerId];
$quote->setCustomerNote(_NOTES_);
$quote->setCouponCode(_COUPON_CODE_);
$product = $this->_product->load('PRODUCT_ID'); //PRODUCT_ID= xx
$params = [];
$params['product'] = $productId;
$params['qty'] = intval($qty);
$options = [];
$options[_ATTRIBUTE_] = _VALUE_] ;
$params['super_attribute'] = $options;
$config = new MagentoFrameworkDataObject();
$config->setItem($params);
$quote->addProduct($product,$config);
$quote->save();
How to Save items in cart now ??
So when user login into account able to view items in cart.
2
Answers
Here is answer I have got it working :
Change $quote->save(); to $quote->collectTotals()->save();
after that load quote id and update updated_at field date to same as created date. Now login and check your cart. Item will be viewed there.
This is how you need to add product to cart.
Once product is added to the cart, the you can save it to the quote.