2013-04-29 121 views
1

由於某種原因,我需要包括非待售產品在內的所有產品。但我不確定這是否是magento沒有顯示的唯一情況。如何將不可銷售的產品添加到產品集合中

目前我得到的所有退貨產品都有現貨,並有正常產品的價格等。

收集不拾起非銷售或沒有價格的產品。這是我們創造的一種不同類型的產品,價格不是快照中的強制選項。

category containing 2 products

現在,我想這兩種產品的集合。 目前,我只得到一個價格顯示,底部一個。

我試圖

<?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; 
    } 
} 

}

使用這個它沒有顯示任何東西。空白頁。但如果我從getCollection()方法中刪除 - > addAttributeToFilter('is_saleable',array('like'=>'0')),那麼我會得到包含一個產品的正常集合。 var_dump下面。

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 

請建議。謝謝

以下是這個產品類型的差異沒有任何價格輸入的選項,以便人們不能將其添加到購物車,沒有價格顯示。它就像一個cms頁面一樣。當我們在產品列表頁面中點擊它時,它會轉到產品頁面,而沒有添加到購物車選項。這是從產品清單和所有這一切。

但我想在主頁上調用這些產品,並且所有其他產品都顯示,但不是這個。

enter image description here

enter image description here

----配置。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> 
+0

試' - > addAttributeToFilter(「is_saleable」,陣列(「gteq」 =>「0」))',這將讓所有可銷售的產品,以及不可售 – Kalpesh 2013-04-29 10:20:16

+0

我試過沒工作 – RIK 2013-04-29 15:13:10

回答

1

它散發出來的問題是,在我的這個方法我的「內」字。刪除它後,我的所有產品都在我的收藏中。

$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

Magento的檢查,如果產品(庫存股),無論數量,如果{產品[stock_data] [is_in_stock]}是真的,這將是合格的產品,如果是假的也不會出售(不管量)

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

添加此行代碼產品採集前

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

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

會告訴目錄產品型號isAvailabe方法跳過isSalable支票下面的方法

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

我還沒有嘗試過這個解決方案。它是否自動收集不顯示產品不可售?如果magento檢查產品是否出售,該如何檢查? – RIK 2013-04-29 15:12:06

+0

如果{product [stock_data] [is_in_stock]}爲真,那麼Magento會檢查產品(庫存是否爲庫存),否則這是可銷售的產品,如果它爲假,則不會銷售(不管數量如何) – Meabed 2013-04-29 18:07:05

+0

不,案子。我編輯了這個問題,請檢查。感謝 – RIK 2013-04-30 07:50:32