0

Using Magento 1.8v.

In my customization when customer adding products to cart. Some products qty should not be changeable (i.e qty is fixed) and some other products qty available to change .

Example :

cat1 
  products 
cat2
  subcat
    products
  subcat
    products
cat3
  subcat
     products

For Example: cat1 products allowed for qty change so when adding to shopping cart it will be 1 and remaining category should not allowed so it is stock item value .

Im trying below code in this class Mage/Checkout/Model/Cart.php but throwing error

$categoryIds=$this->getProduct()->getCategoryIds($productid);
    foreach($categoryIds as $categoryId)    
    $category = Mage::getModel('catalog/category')->load($categoryId);
    if ($category->getName() == 'cat1')   
        $minimumQty = $product->getStockItem()->getMinSaleQty();  
   else if($category->getName() == 'cat2')                        
         minimumQty=stock_item->loadByProduct($product)->getQty();   

How do i get category name ?

2 Answers 2

1

Try this.

// Get category id by product id.
    $quote = Mage::getModel('checkout/cart')->getQuote();
    $items = $quote->getAllVisibleItems();
    $count = 0;
    foreach ($items as $item) {
        $product = $item->getProduct();
        if ($count < 10) {
            $categories = $product->getCategoryCollection()
                        ->addAttributeToSelect('name')
                        ->addAttributeToFilter('is_active', array('eq' => 1));
            foreach($categories as $cat) {
                if(trim($cat) == 'xxx') { // If category_name == 'xxx' 
                    // Do something.
                    break;
                }
            }
            $count++;
        } else {
            break;
        }
    }
0

QuoteItems have app/code/core/Mage/Sales/Model/Quote/Item.php a method called getProductId. You might load the Products and consequently it's categories by looping over the QuoteItems.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.