题
我现在看了一段时间,但我找不到任何解决方案。 Magento愿望单总是用新添加的项目替换现有的愿望清单项目。
SELECT * FROM wishlist_item WHERE wishlist_id LIKE 4578
.
显示另一个项目。
生成addurl的部分:
app\design\frontend\[mytheme]\default\template\catalog\product\view\addto.phtml.
<?php
$_product = $this->getProduct();
$_wishlistSubmitUrl = $this->helper('wishlist')->getAddUrl($_product);
?>
<ul class="wishlist-recommend-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li>
<a href="<?php echo $_wishlistSubmitUrl ?>" onclick="productAddToCartForm.submitLight(this, this.href); return false;" class="add-to-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
</li>
<?php endif; ?>
<li>
<a href="<?php echo $this->helper('catalog/product')->getEmailToFriendUrl($_product) ?>" class="recommend fancybox" data-type="iframe" data-fancybox-width="480" data-fancybox-height="90%"><?php echo $this->__('Recommend product') ?></a>
</li>
</ul>
.
将显示愿望清单的部分:
\app\design\frontend\[mytheme]\default\template\wishlist\item\list.phtml.
<?php
$columns = $this->getColumns();
?>
<table class="data-table cart-table" id="wishlist-table">
<thead>
<tr>
<?php foreach ($columns as $column): ?>
<th><?php echo $column->getTitle();?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php if (count($this->getItems())): ?>
<?php foreach ($this->getItems() as $item): ?>
<tr id="item_<?php echo $item->getId();?>">
<?php foreach ($columns as $column): ?>
<td><?php $column->setItem($item); echo $column->toHtml($item);?></td>
<?php endforeach; ?>
</tr>
<?php endforeach ?>
<?php else: ?>
<td colspan="<?php echo count($columns);?>" class="wishlist-empty"><?php echo $this->__('This Wishlist has no Items');?></td>
<?php endif; ?>
</tbody>
</table>
<?php foreach ($columns as $column): ?>
<?php echo $column->getAdditionalHtml();?>
<?php endforeach; ?>
<script type="text/javascript">
//<![CDATA[
decorateTable('wishlist-table');
<?php foreach ($columns as $column): ?>
<?php echo $column->getJs();?>
<?php endforeach; ?>
//]]>
</script>
.
有人对此有同样的问题,可能是一个解决方案吗?
解决方案
尝试覆盖核心类 mage_wishlist_model_resource_item_collection 和 mage_catalog_model_resource_product_collection 根据diff:
mage_wishlist_model_resource_item_collection
.
@@ -184,9 +184,13 @@
$this->_productIds = array_merge($this->_productIds, array_keys($productIds));
$attributes = Mage::getSingleton('wishlist/config')->getProductAttributes();
- $productCollection = Mage::getModel('catalog/product')->getCollection();
+
+ /** @var Mage_Catalog_Model_Resource_Product_Collection $productCollection */
+ $productCollection = Mage::getModel('catalog/product')->getCollection()
+ ->setUseLeftJoinForPriceIndex(true);
+
foreach ($storeIds as $id) {
- $productCollection->addStoreFilter($id);
+ $productCollection->addWebsiteFilter(Mage::app()->getStore($id)->getWebsiteId());
}
if ($this->_productVisible) {
和 mage_catalog_model_resource_product_collection :
.@@ -132,13 +132,20 @@
protected $_productCountSelect = null;
/**
- * Enter description here ...
+ * Is website filter
*
* @var bool
*/
protected $_isWebsiteFilter = false;
/**
+ * Type of joining price index table
+ *
+ * @var bool
+ */
+ protected $_useLeftJoinForPriceIndex = false;
+
+ /**
* Additional field filters, applied in _productLimitationJoinPrice()
*
* @var array
@@ -1759,11 +1766,15 @@
/**
* Join Product Price Table with left-join possibility
*
+ * @param bool|null $joinLeft
+ *
* @see Mage_Catalog_Model_Resource_Product_Collection::_productLimitationJoinPrice()
* @return Mage_Catalog_Model_Resource_Product_Collection
*/
- protected function _productLimitationPrice($joinLeft = false)
+ protected function _productLimitationPrice($joinLeft = null)
{
+ $joinLeft = is_null($joinLeft) ? $this->_useLeftJoinForPriceIndex : $joinLeft;
+
$filters = $this->_productLimitationFilters;
if (empty($filters['use_price_index'])) {
return $this;
@@ -2172,4 +2183,18 @@
return $this->_pricesCount;
}
+
+ /**
+ * Set type of joining price index table
+ *
+ * @param bool $value
+ *
+ * @return Mage_Catalog_Model_Resource_Product_Collection
+ */
+ public function setUseLeftJoinForPriceIndex($value)
+ {
+ $this->_useLeftJoinForPriceIndex = (bool)$value;
+
+ return $this;
+ }
}