創建一個外部腳本來導入行情/購物車(其他CMS)。我的代碼能夠添加報價但不能創建購物車。當用戶登錄到他們的帳戶時需要顯示所有報價項目。我也啓用了持久性購物車。導入報價並將產品添加到購物車中Magento 2
class QuoteMove extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface
public function __construct(
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Framework\Event\Manager $eventManager,
\Magento\Framework\App\AreaList $areaList,
\Magento\Framework\App\Request\Http $request,
\Magento\Framework\App\Response\Http $response,
\Magento\Framework\ObjectManager\ConfigLoaderInterface $config,
\Magento\Framework\App\State $state,
\Magento\Framework\Filesystem $fileSystem,
\Magento\Framework\Registry $registry,
\Magento\Store\Model\Store $store,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\File\Csv $csvProcessor,
\Magento\Quote\Model\QuoteFactory $quote,
\Magento\Catalog\Model\Product $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 \Magento\Framework\DataObject();
$config->setItem($params);
$quote->addProduct($product,$config);
$quote->save();
How to Save items in cart now ??
所以當用戶登錄賬戶後就可以查看購物車中的物品。
此代碼是當他離線時從外部將購物車注入客戶帳戶,以便當客戶登錄時,他可以在購物車中看到該物品。例如:我們添加到購物車項目,然後註銷並重新登錄購物車。用其他方式從舊數據庫或其他數據庫導入magento2。你的代碼不適合這種情況。 – Vikram