[英]Magento2 Get Simple SKU When AddToCart
当我添加到购物车时,我试图获取一个简单产品的SKU。 我有一个可配置的产品,其中有3个尺寸选项S,M,L。 每个都有自己的SKU,当我选择尺寸并单击“添加到购物车”时,我要获取简单产品的sku。
我看过js文件catalog-add-to-cart.js,它不返回简单的sku,而仅返回可配置的sku。
但是,在控制台中,有来自http://mywebsite.com/customer/section/load/?sections=cart%2Cmessages&update_section_id=true的响应
确实包含简单的SKU。
有人可以告诉我一种快速捕获简单SKU的方法吗?
提前致谢!
我使用了这一小调整来获取简单产品的SKU,而不是如果有多种尺寸或颜色的产品则不是可配置的
//By default, use the default product image
$path = Mage::helper('catalog/image')->init($product, 'small_image');
//BUT
//If there is multiple colors/sizes
if (is_array($product["_cache_instance_products"])){
//For each product in the inventory
foreach ($product["_cache_instance_products"] as $_prod ) {
//check if the SKU match with the one of the article in the Cart
if($_prod["sku"]==$product->getSku()){
//check if this product have various color
if (isset($_prod["small_image"])){
//if so, take the specific image
$path = Mage::helper('catalog/image')->init($_prod, 'small_image');
}
}
}
}
这段代码位于: shop / app / code / community / Mdl / Ajaxcheckout / controllers / IndexController.php
希望对您有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.