我对此有意见。虽然我得到了解决方案,但我仍然想知道它到底为什么会捕捉到它。我有一个Magento的桌面版本和移动版本的网站。在分类页面上,它显示了您所知道的产品列表。现在,出现了一个问题
我得到每个产品的结构如下:
Product Name
Image
Regular Price
Special Price移动版可以,但台式机版没有特价。我以前写过代码
"$product->getSpecialPrice()" 来获得它,但不起作用。这些版本的不同之处只是来自前端,所有来自后端的功能都是相同的。确切地说,产品数据由相同的函数检索
getLoadedProductCollection()Magento Core的产品列表块。所以,我真的不能理解为什么我可以在移动版中通过调用$product->getSpecialPrice()来获取特价的值,而不是在桌面版中。
请帮帮我,谢谢。
发布于 2014-05-13 17:35:23
<?php
include_once 'app/Mage.php';
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);
$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
foreach($_productCollection as $_product){
if($_product->getData('special_price')!=null){
echo '<img src="'.$this->helper('catalog/image')->init($_product, 'thumbnail')->resize(75).'" alt="'.$_product->getName().'" /><br />';
echo $_product->getName().'<br />';
$specialPrice = $_product->getData('special_price');
$orignalPrice = $_product->getData('price');
echo number_format($specialPrice, 2)."<br/>";
echo number_format($orignalPrice, 2)."<br/>";
echo '<a href="http://www.yourwebsite.com/magento/checkout/cart/add?product='.$_product->getId().'&qty;=1">Add To Cart</a><br />';
}
}
?> 发布于 2016-04-15 12:01:01
只需使用getFinalPrice而不是getSpecialPrice。:D
https://stackoverflow.com/questions/23627087
复制相似问题