2
votes

For some reason I need all the products in collection from a category including product not for sale. But I am not really sure if that is the only case magento is not displaying it.

At the moment I am getting all products returned which are in stock and have price etc, like normal products.

collection is not picking up products which are not for sale or have no price given. It's a different type of product we have created where price is not a mandatory option as in snapshot.

category containing 2 products

Now I want both of these products in collection. At the moment I am only getting the one with the price shown, bottom one.

I tried

<?php


class Ubt_Featured_Block_Featured extends
Mage_Core_Block_Template {

private $_itemPerPage = 2;
private $_category_id = 4;

public function allProducts() {


    $category = Mage::getModel('catalog/category')->load($this->_category_id);
    $_collections = $category->getProductCollection();
    $_productCollection = $this->getCollection($_collections);  // calling the function that have been created in block page.

    return $_productCollection;
}

public function totalPages() {
    $category = Mage::getModel('catalog/category')->load(4);
    $_collections_count = $category->getProductCollection()->count();
    return $number_of_pages = $_collections_count / $this->_itemPerPage;
}

public function getCollection($collection = 'null') {

    if ($collection != 'null') {


        $collection->addWebsiteFilter();
        $collection->addUrlRewrite($this->_category_id);
        $collection->addMinimalPrice()->addFinalPrice()->addTaxPercents();

        Mage::getSingleton('catalog/product_visibility')
                ->addVisibleInCatalogFilterToCollection($collection);

        Mage::getSingleton('catalog/product_status')
                ->addVisibleFilterToCollection($collection);

        $collection->addAttributeToSelect(array('entity_id', 'sku', 'name', 'short_description', 
            'description', 'price', 'thumbnail', 'image', 'url_path', 'type_of'), 'inner')
              ->addAttributeToFilter('is_saleable', array('like' => '0'))      ;


        $collection->setCurPage(1);
        $collection->setPageSize($this->_itemPerPage);

        return $collection;
    }
}

}

it not showing anything using this. blank page.

But if I remove the ->addAttributeToFilter('is_saleable', array('like' => '0')) from getCollection() method then I get the normal collection containing one product. var_dump below.

    array
  'entity_id' => string '1' (length=1)
  'entity_type_id' => string '4' (length=1)
  'attribute_set_id' => string '4' (length=1)
  'type_id' => string 'simple' (length=6)
  'sku' => string 'q' (length=1)
  'has_options' => string '0' (length=1)
  'required_options' => string '0' (length=1)
  'created_at' => string '2013-03-05 22:00:39' (length=19)
  'updated_at' => string '2013-04-29 01:29:30' (length=19)
  'cat_index_position' => string '0' (length=1)
  'grant_catalog_category_view' => string '-1' (length=2)
  'grant_catalog_product_price' => string '-1' (length=2)
  'grant_checkout_items' => string '-1' (length=2)
  'price' => string '22.0000' (length=7)
  'tax_class_id' => string '2' (length=1)
  'final_price' => string '22.0000' (length=7)
  'minimal_price' => string '22.0000' (length=7)
  'min_price' => string '22.0000' (length=7)
  'max_price' => string '22.0000' (length=7)
  'tier_price' => null
  'name' => string 'Prod 01' (length=7)
  'short_description' => string 'q' (length=1)
  'description' => string 'q' (length=1)
  'thumbnail' => string '/h/a/hands.jpg' (length=14)
  'image' => string '/h/a/hands.jpg' (length=14)
  'url_path' => string 'prod-01.html' (length=12)
  'type_of' => null
  'request_path' => string 'sub-cat-01/prod-01.html' (length=23)
  'is_salable' => string '1' (length=1)
  'stock_item' => 
    object(Varien_Object)[546]
      protected '_data' => 
        array
          'is_in_stock' => string '1' (length=1)
      protected '_hasDataChanges' => boolean false
      protected '_origData' => null
      protected '_idFieldName' => null
      protected '_isDeleted' => boolean false
      protected '_oldFieldsMap' => 
        array
          empty
      protected '_syncFieldsMap' => 
        array
          empty
  'tax_percent' => float 10
  'category_ids' => 
    array
      0 => string '2' (length=1)
      1 => string '3' (length=1)
      2 => string '4' (length=1)
  'event' => boolean false

Please suggest. Thank you

Here is the difference this product type doesn't not have any option of price input, so that people can not add it to the cart and no price to display. It is just same like a cms page. when we click on it in the product listing page it takes to to the product page with no add to cart option. This is working from in the product listing and all that.

But I am trying to calling these product on the homepage and all others are showing but not this one.

enter image description here

enter image description here

----config.xml

    <?xml version="1.0"?>

<config>
    <modules>
        <Rik_ReferralProduct>
            <version>0.1.0</version>
        </Rik_ReferralProduct>
    </modules>
    <global>
        <models>
            <referralproduct>
                <class>Rik_ReferralProduct_Model</class>
            </referralproduct>
        </models>
        <catalog>
            <product>
                <type>
                    <referralproduct translate="label" module="catalog">
                        <label>Referral Product</label>
                        <model>referralproduct/product_type_referral</model>
                        <is_qty>1</is_qty>
                        <index_data_retreiver>referralproduct/catalogIndex_data_referral</index_data_retreiver>
                        <composite>0</composite>
                    </referralproduct>
                </type>
            </product>        
        </catalog>
        <blocks>
            <adminhtml>
                <rewrite>
                    <catalog_product_edit_tabs>Rik_ReferralProduct_Block_Adminhtml_Catalog_Product_Edit_Tabs</catalog_product_edit_tabs>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
    <!--<adminhtml>-->
        <!--<layout>-->
            <!--<updates>-->
                <!--<referralproduct>-->
                    <!--<file>referral.xml</file>-->
                <!--</referralproduct>-->
            <!--</updates>-->
        <!--</layout>-->
    <!--</adminhtml>-->
</config>
2
try ->addAttributeToFilter('is_saleable', array('gteq' => '0')), which will get all the products with saleable as well as non-saleableKalpesh

2 Answers

1
votes

It comes out that the problem was with my 'inner' word in my this method. after removing it I've got all my products in my collection.

    $collection->addAttributeToSelect(array('entity_id', 'sku', 'name', 'short_description', 
        'description', 'price', 'thumbnail', 'image', 'url_path', 'type_of'), 'inner')
          ->addAttributeToFilter('is_saleable', array('like' => '0'))      ;
0
votes

Magento check if Product ( inventory is stock ) regardless the quantity, if { product[stock_data][is_in_stock] } is true this will be salable product, if it false it won't salable ( regardless the quantity )

===========================

Adding this line of code before your product collection

Mage::helper('catalog/product')->setSkipSaleableCheck(true);

============================

Will tell the catalog product model isAvailabe method to skip isSalable check in the method below

public function isAvailable()
{
    return $this->getTypeInstance(true)->isSalable($this)
        || Mage::helper('catalog/product')->getSkipSaleableCheck();
}