如何将不可销售的产品添加到产品集合中

时间:2013-04-29 06:12:06

标签: magento

出于某种原因,我需要从包括非销售产品在内的所有产品中收集产品。但我不确定这是否是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()方法中删除 - &gt; addAttributeToFilter(&#39; is_saleable&#39;,数组(&#39;喜欢&#39; =&gt;&#39; 0&#39;))然后我得到包含一个产品的正常集合。 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

---- 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 个答案:

答案 0 :(得分: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'))      ;

答案 1 :(得分:0)

Magento检查产品(库存是库存),无论数量是多少,如果{product [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();
}