总是计算Magento中产品集合的返回值0(零)

编程入门 行业动态 更新时间:2024-10-25 19:35:18
本文介绍了总是计算Magento中产品集合的返回值0(零)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

实际上,我正在尝试查找该产品是否在愿望清单中.所以我在Stack Overflow问题 ,但是产品集合始终返回0.

Actually, I am trying to find if this product is in a wishlist or not. So I tried Daniel Sloof's answer in StackOverflow 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(零)

本文发布于:2023-10-19 19:21:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1508517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   产品   Magento

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!