创建一个外部脚本来导入行情/购物车(其他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