我为这些产品增加了特价。它在产品详细信息页面上显示特价但未在类别页面上显示。如果我在list.phtml上调用specialprice而不是只显示0.我认为需要在list.php中进行一些更改。
代码如下: - 在list.php中,我的功能是
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$layer = $this->getLayer();
/* @var $layer Mage_Catalog_Model_Layer */
if ($this->getShowRootCategory()) {
$this->setCategoryId(Mage::app()->getStore()->getRootCategoryId());
}
// if this is a product view page
if (Mage::registry('product')) {
// get collection of categories this product is associated with
$categories = Mage::registry('product')->getCategoryCollection()
->setPage(1, 1)
->load();
// if the product is associated with any category
if ($categories->count()) {
// show products from this category
$this->setCategoryId(current($categories->getIterator()));
}
}
$origCategory = null;
if ($this->getCategoryId()) {
$category = Mage::getModel('catalog/category')->load($this->getCategoryId());
if ($category->getId()) {
$origCategory = $layer->getCurrentCategory();
$layer->setCurrentCategory($category);
$this->addModelTags($category);
}
}
$this->_productCollection = $layer->getProductCollection();
$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());
if ($origCategory) {
$layer->setCurrentCategory($origCategory);
}
}
return $this->_productCollection;
}
list.phtml
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<div class="products-grid">
<div class="row">
<?php $i=0; foreach ($_productCollection as $_product):
$id_product = Mage::getModel('catalog/product')->load($_product->getId());
//$count_input_qty++;
$now = date("Y-m-d");
$newsFrom = substr($_product->getData('news_from_date'), 0, 10);
$newsTo = substr($_product->getData('news_to_date'), 0, 10);
$specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
//echo $specialprice . '-hau<br/>';
$price = Mage::getModel('catalog/product')->load($_product->getId())->getPrice();
if ($specialprice == '') {
$store_id = Mage::app()->getStore()->getStoreId();
$discounted_price = Mage::getResourceModel('catalogrule/rule')->getRulePrice(
Mage::app()->getLocale()->storeTimeStamp($store_id),
Mage::app()->getStore($store_id)->getWebsiteId(),
Mage::getSingleton('customer/session')->getCustomerGroupId(),
$_product->getId());
$specialprice = $discounted_price;
}
?>
<?php if ($i++%$_columnCount==0): ?>
<?php endif ?>
<div class="item col-lg-4 col-md-4 col-sm-6 col-xs-6 respl-item">
<div class="item-inner">
<div class="w-image-box">
<div class="item-image">
<!--SHOW 2 IMAGE FOR PRODUCTS-->
<?php $_media = Mage::getModel('catalog/product')->load($_product->getId())->getMediaGalleryImages() ?>
<?php $count_item=0; $check_img=0;?>
<?php $check_img = count($_media);?>
<a class="<?php if ($check_img >= 2) echo $this->__('rspl-image');?>" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>">
<img class="first_image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(270); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />
<?php if ($check_img >= 2): ?>
<?php
$flag=0;
foreach($_media as $_img): ?>
<?php $count_item++;?>
<?php if ($_img->getFile() == $_product->getSmallImage()){
if($count_item==$check_img){
$flag = 0;
}else{
$flag = 1;
}
continue;
} ?>
<?php if($flag==1) { ?>
<img class="last_image" src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_img->getFile())->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(270,270); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" />
<?php break; }?>
<?php endforeach; ?>
<?php
if($flag==0){
foreach($_media as $_img){ ?>
<img class="last_image" src="<?php echo $this->helper('catalog/image')->init($_product, 'image', $_img->getFile())->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(270,270); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true); ?>" />
<?php break; }
}
?>
<?php endif?>
<!--END SHOW 2 IMAGE FOR PRODUCTS-->
</a>
</div>
<?php if ($newsFrom != "" && $now >= $newsFrom && ($now <= $newsTo || $newsTo == "")) { ?>
<div class="new-product">
<?php echo $this->__('New'); ?>
</div>
<?php }?>
<?php if ($specialprice) { ?>
<div class='sale-item'>
<?php echo $this->__('Sale'); ?>
</div>
<?php }?>
</div>
<div class="item-info">
<div class="item-title ">
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>">
<?php if( strlen($_helper->productAttribute($_product, $_product->getName(), 'name')) > 100 ){
echo substr($_helper->productAttribute($_product, $_product->getName(), 'name'), 0, 100);
} else {
echo $_helper->productAttribute($_product, $_product->getName(), 'name');
}?>
</a>
</div>
<div class="item-review">
<?php echo $this->getReviewsSummaryHtml($_product, "short", true); ?>
</div>
<div class="item-price">
<?php // echo $this->getPriceHtml($_product, true) ?>
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
<!--
<div class="item-desc">
<?php
echo substr($_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description'), 0, 70);
?>
</div>
-->
<div class="item-addto-wrap">
<div class="button-action item-addcart">
<?php if($_product->isSaleable()): ?>
<a class="button btn-cart" title="<?php echo $this->__('Add to Cart') ?>" href="javascript:void(0);" onclick="setLocation('<?php echo $this->getAddToCartUrl($id_product) ?>')">
<?php echo $this->__('Add to Cart') ?>
</a>
<?php else: ?>
<p class="availability out-of-stock">
<span><?php echo $this->__('Out of stock') ?> </span>
</p>
<?php endif; ?>
<?php if( $_compareUrl=$this->getAddToCompareUrl($_product) ): ?>
<a class="link-compare" href="<?php echo $_compareUrl ?>" title="<?php echo $this->__('Add to Compare'); ?>">
<?php echo $this->__('Add to Compare') ?>
</a>
<?php endif;?>
<?php if ( $this->helper('wishlist')->isAllow() ) : ?>
<a class="link-wishlist" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" title="<?php echo $this->__('Add to Wishlist') ?>">
<?php echo $this->__('Add to Wishlist') ?>
</a>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
<?php endif ?>
<?php endforeach ?>
</div>
</div>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
建议我,我该怎么办?
答案 0 :(得分:1)
重新索引 Timer _timer;
someFunc() {
_timer = new Timer.periodic(const Duration(milliseconds: 1000 /*properties.delay*/),
(_) {
if (this.carouselIndex < this.showcases.length - 1) {
this.carouselIndex = this.carouselIndex + 1;
} else {
this.carouselIndex = 0;
}
});
// to stop the periodic execution use
// _timer.cancel();
}
即使"Category Products"
&amp; Status = Ready
答案 1 :(得分:0)
我记得在产品浏览页面上所有价格都是即时收集的。但是在包含许多产品(网格/列表)的页面上,价格来自数据库。 这意味着您的代码最有可能没有问题。您的数据库中存在问题。尝试重新索引,重新保存,检查数据库中的值。
还尝试禁用任何可能影响计算价格过程的模块,然后重新编制索引并重新保存。打开系统/设计中的默认主题。
希望它会有所帮助。