Magento-単一の製品ビューでツールバーを表示したり、サイドバーを破ったりしない特別コレクション

magento.stackexchange https://magento.stackexchange.com/questions/3096

  •  16-10-2019
  •  | 
  •  

質問

私は、店に追加された新製品の両方と割引になっているものの両方を示す2ページの2つのページが必要なMagentoストアを持っています。どちらも同じ問題を示していますが、それが最も問題があると思うので、後者のコードを提供します。

問題は、基準を示す製品のリストを成功させることができますが、他のカテゴリのようにツールバーを表示することはできません。また、そこから製品をクリックすると、製品の詳細ページでサイドバーを失います。まるで設定したXMLルールが、プロモーションページからコミットしているため、ページに適用されないかのようです。

これは、プロモーションがアクティブな製品のコレクションを取得するために使用するクラスです。

class Mage_Catalog_Block_Product_Promo extends Mage_Catalog_Block_Product_List{
protected $_productsCount = null;

const DEFAULT_PRODUCTS_COUNT = 5;

protected function _beforeToHtml()
{
    $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

    $collection = Mage::getResourceModel('catalog/product_collection');
    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);

    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
        ->addAttributeToFilter('special_to_date', array('or'=> array(
            0 => array('date' => true, 'from' => $todayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
        ), 'left')
        ->addAttributeToSort('flash', 'desc')
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1)
    ;
    $this->setProductCollection($collection);

    $toolbar = $this->getToolbarBlock();
    $toolbar->setCollection($collection);
    $this->setChild('toolbar', $toolbar); 

    return parent::_beforeToHtml();
}

 public function setCollection($collection)
{
    $this->_productCollection = $collection;
    return $this;
}

public function setProductsCount($count)
{
    $this->_productsCount = $count;
    return $this;
}

public function getProductsCount()
{
    if (null === $this->_productsCount) {
        $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;
    }
    return $this->_productsCount;
}
} 

これは私のPHTMLで、私はすべての製品を手に入れます:

<?php $current_cat= Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); ?>

<?php 
$_productCollection = $this->getProductCollection();
$_helper = $this->helper('catalog/output');
$_collectionSize = $_productCollection->count() ?>
<div class="promos_new_list">
    <div class="countcat">
        <?php //$_productCollection = $this->getLoadedProductCollection(); 
        $count = $_productCollection->getSize(); 
        echo $count; ?> Produits 
    </div>
<?php echo $this->getToolbarHtml(); ?>
<?php $_columnCount = 4; ?>
<?php $i=0; 
foreach ($_productCollection as $_product): ?>
    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid">
    <?php endif ?>
        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
            <?php include('view/labels.phtml')  ?>                
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(178,108); ?>" width="178" height="108" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
            <div id="productimgover<?php echo $_product->getId()?>" style="display: none;"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(64); ?>" width="64" height="64" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></div>
            <div class="moreinfo">
                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
                <div id='productname<?php echo $_product->getId()?>' style='display:none'><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></div>
                <p class="product-desc">
                    <?$desc=$this->htmlEscape($_product->getShortDescription());?>
                    <?php echo Mage::helper('function')->unalinea($desc,30);?>
                </p>
                <?php echo $this->getPriceHtml($_product, true) ?>

                <div class="nowmore orangegradient">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">En savoir plus </a><span></span>
                </div>

                <div class="clear"></div>

            </div>
        </li>
    <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
    </ul>
    <?php endif ?>
<?php endforeach ?>
</div>

これ以上コードが必要かどうかはわかりません。同僚は、Magentoがアクティブなカテゴリを持っていないのでこれを行うとき、Magentoは正しく機能していないと言いますが、理由は本当にわかりませんか?ここで私を導いてもらえますか?

役に立ちましたか?

解決

これまでのところ、これを使用してツールバーの問題を避けました。

<?php
$toolbar = Mage::getBlockSingleton('catalog/product_list')->getToolbarBlock();
$toolbar->setCollection($_productCollection);
echo $toolbar->toHtml();
?>

それが状況に近づく正しい方法であるかどうかはわかりませんが、今のところ私にとってはうまくいきます。

ライセンス: CC-BY-SA帰属
所属していません magento.stackexchange
scroll top