总是计算Magento中产品集合的返回值0(零) [英] Always count return 0 (zero) from a product collection in Magento
本文介绍了总是计算Magento中产品集合的返回值0(零)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
实际上,我正在尝试查找该产品是否在愿望清单中.所以我在Stack Overflow问题
Actually, I am trying to find if this product is in a wishlist or not. So I tried Daniel Sloof's answer in Stack Overflow question Check whether a product is in the wishlist or not, but the product collection always returns 0.
我尝试过的是这里
$_productCollection1 = Mage::helper('wishlist')
->getProductCollection()
->addFieldToFilter('sku','00114477oo0077');
$_productCollection1->count();
这个返回"0".
要调试,我在返回一行时直接在数据库中应用查询.
To debug, I print the query in directly applied in my database in returning one row.
使用
$_productCollection1->getSelect()->assemble()
并查询
SELECT `e` . * , `cat_index`.`position` AS `cat_index_position`
FROM `catalog_product_entity` AS `e`
INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id = e.entity_id
AND cat_index.store_id = '1'
AND cat_index.visibility
IN ( 3, 2, 4 )
AND cat_index.category_id = '2'
WHERE (
e.sku = '00114477oo0077'
)
那么这里出了什么问题?还有其他方法吗?
So what's is wrong here? Is there any other way to do this?
推荐答案
我通过以下功能解决了这个问题.
I solved this by the below function.
function checkInWishilist($_product){
Mage::getSingleton('customer/session')->isLoggedIn();
$session = Mage::getSingleton('customer/session');
$cidData = $session->isLoggedIn();
$customer_id = $session->getId();
if ($customer_id){
$wishlist = Mage::getModel('wishlist/item')->getCollection();
$wishlist->getSelect()
->join(array('t2' => 'wishlist'),
'main_table.wishlist_id = t2.wishlist_id',
array('wishlist_id','customer_id'))
->where('main_table.product_id = '.$_product->getId().' AND t2.customer_id='.$customer_id);
$count = $wishlist->count();
$wishlist = Mage::getModel('wishlist/item')->getCollection();
}
else{
$count="0";
}
if ($count):
return true;
else:
return false;
endif;
}
这篇关于总是计算Magento中产品集合的返回值0(零)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文