1 Comment

Get Product collection with attribute value equal to null

Adding to cart from external site
magento crossdomain issue fething data using ajax from others domains

I have product attribute called ‘category_3’ with value ‘kids’ or null.i wanted only those products with an attribute ‘category_3’ value equals to null.my query is as follows:-

$products = Mage::getModel('catalog/category')->load(40)
            ->getProductCollection()
            ->addAttributeToSelect('*')
            ->addAttributeToFilter('status', 1)
            ->addAttributeToFilter('visibility', 4)
            ->setOrder('price', 'ASC');

i had tried following options and i am not getting the products with the category_3 value as null

// ->addAttributeToFilter('category_3',array('NULL' => true))
    //->addAttributeToFilter('category_3',array('eq'=>'NULL'))
    // ->addAttributeToFilter('category_3','')

Related Posts

  • I need first where condition result in first and then second in magento product collection (0)
    I have one collection $this->_collection in toolbar.php I have one collection in a method where I want to perform two different operations on this collection. So, I want two separate copies of same collection $select1 = clone […]
  • Get Categories of Products on Special Offer (4)
    How can I get the list of categories of all the products on special offers. It's a bit tricky. I'm able to get the list of products using: $collection ->addAttributeToFilter( array( array('attribute' => 'news_from_date', […]
  • Get Categories of Products on Special Offer (4)
    How can I get the list of categories of all the products on special offers. It's a bit tricky. I'm able to get the list of products using: $collection ->addAttributeToFilter( array( array('attribute' => 'news_from_date', […]
  • Merge Same Product collection with different where clause magento (0)
    I am doing this this way. $select1 = clone $this->_collection; $select1->getSelect()->joinInner(array('ccc' => $tablename),'e.entity_id = ccc.entity_id')->where("ccc.product_primary_category=".$cateid); $selectOneSql = […]
  • How to set order by custom formula for product collection (0)
    I have product collection which have group price for customer_group_id 3 using below code $sql = 'select distinct entity_id from catalog_product_entity_group_price where customer_group_id = 3'; $resource = Mage::getSingleton('core/resource'); $readConnection = […]
  • Magento re-index sql query wont finish (1)
    We are having troubles with our Magento 1.9.1.1 re-indexing process. Sometimes it starts a query which will not finish - once i had to kill it after about 33 hours of execution because the server performance suffered from it. The strange thing is, that this query is not started on […]
  • Is there anyway to restrict min qty limit for config product? (0)
    I know you can restrict the max/min limit when adding a simple product to cart, however I wish to restrict the config product as a whole. I sell T Shirts for printing and there needs to be a minimum quantity of 6. When I restrict the simple products, it means that it will only […]
  • Add item to cart and product options (0)
    I want to add item to cart programatically so I used this piece of code. $result = $proxy->shoppingCartProductAdd($sessionId, 4, array(array( 'product_id' => '4', 'sku' => 'simple_product', 'qty' => '5', 'options' => array( 13 => '1000', […]
  • Create product collection in PHTML with filter based on Category ID (1)
    We want to get a Product Collection based on a filter with the category ID. In our case, we have the desired Category with ID 43. Our Call looks like this: $objectManager = MagentoFrameworkAppObjectManager::getInstance(); $productCollection = […]
  • Im getting an error when trying to open manage attributes (0)
    a:5:{i:0;s:409:"SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'is_visible_on_front' in where clause is ambiguous, query was: SELECT COUNT(*) FROM `eav_attribute` AS `main_table` INNER JOIN `catalog_eav_attribute` AS `additional_table` ON additional_table.attribute_id […]
Adding to cart from external site
magento crossdomain issue fething data using ajax from others domains

1 Comment on this article

  • User November 12, 2016

    Add your attribute to product collection using below code

    <config>
        <frontend>
            <product>
                <collection>
                    <attributes>
                        <category_3 />
                    </attributes>
                </collection>
            </product>
        </frontend>
    </config>
    

    after adding attribute to collection using below code you can filter collection

    $products = Mage::getModel('catalog/category')->load(40)
                ->getProductCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('category_3',array('null' => true))
                ->addAttributeToFilter('status', 1)
                ->addAttributeToFilter('visibility', 4)
                ->setOrder('price', 'ASC');
    

    Reply

Add a comment