我知道在Magento 1中你可以通过id将产品添加到购物车:
<a href="<?php echo Mage::getUrl("checkout/cart/add/product/4671/")?>
我如何在Magento 2中做同样的事情?
答案 0 :(得分:1)
//你可以像这样使用
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productHelper = $objectManager->get('\Magento\Catalog\Model\Product');
// get product object if you are not having
$product = $productHelper->load($id);
$listBlock = $objectManager->get('\Magento\Catalog\Block\Product\ListProduct');
echo $listBlock->getAddToCartUrl($product);