2016-06-21 40 views
0

在Magento中有什么方法可以检查购物车或报价对象是否已将产品分组 或 我还可以询问购物车中添加的产品是否为分组产品的一部分。检查购物车是否有任何分组产品

有没有办法通过代码来测试。

回答

0

我不知道这是最好的或没有,但你可以用下面的代码:

$groupedParentsIds = Mage::getResourceSingleton('catalog/product_link') 
        ->getParentIdsByChild(enter id of product in cart here, Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED); 

如果标识由您输入有家长则产品组合产品的一部分。

您可以检查您的购物车中的每个产品。

+0

不,那会有点漫长的过程。不建议。非常感谢您的建议。 – arushi

0
$quote = Mage::getSingleton('checkout/session')->getQuote(); 
$cartItems = $quote->getAllVisibleItems(); 
foreach ($cartItems as $item){ 
    if($item->getProduct()->getTypeId()=="bundle") 
     echo "This is a bundle product"; 
    if($item->getProduct()->getTypeId()=="grouped") 
     echo "This is a grouped product"; 
    if($item->getProduct()->getTypeId()=="configurable") 
     echo "This is a configurable product"; 
    if($item->getProduct()->getTypeId()=="virtual") 
     echo "This is a virtual product"; 
    if($item->getProduct()->getTypeId()=="simple") 
     echo "This is a simple product"; 
    if($item->getProduct()->getTypeId()=="downloadable") 
     echo "This is a downloadable product"; 
    if($item->getProduct()->getTypeId()=="giftcard") //in enterprise 
     echo "This is a giftcard product"; 

} 

您也可以设立观察员观看checkout_cart_add_product_complete事件

+0

我知道捆绑产品,我需要分组产品。 – arushi

0

在分组的产品有两个部分

父产品

儿童产品

在车我们只能添加儿童产品。因此,您必须检查购物车是否包含使用以下代码的任何组产品。

Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($productId); 
0

您可以使用下面的代码,以找出是否在车包含任何组合产品:

$quote = Mage::getSingleton('checkout/session')->getQuote(); 
$cartItems = $quote->getAllVisibleItems(); 
foreach ($cartItems as $item){ 
    $productId = $item->getProduct()->getId(); 
    $ids = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($productId); 
    if(isset($ids) && !empty($ids))  
    { 
     echo "This is a grouped product"; 
    } 
} 
相关问题