我试图显示产品的数量,这是与一个博客相关的鱼猪。
我正在尝试下面的方法,但它正在返回空值。
$post->getAssociatedProducts(); 函数
public function getAssociatedProducts($post)
{
if ($post instanceof Fishpig_Wordpress_Model_Post) {
$productIds = $this->_getAssociatedWpEntityIds($post->getId(), 'product', 'post', 'post_id');
try {
foreach($post->getParentCategories() as $category) {
$productIds = array_merge($productIds, $this->_getAssociatedWpEntityIds($category->getId(), 'product', 'category', 'category_id'));
}
}
catch (Exception $e) {
$this->log($e->getMessage());
}
if (count($productIds) > 0) {
$collection = Mage::getResourceModel('catalog/product_collection');
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
$collection->addAttributeToFilter('status', 1);
$collection->addAttributeToFilter('entity_id', array('in' => $productIds));
return $collection;
}
}
return false;
}这会返回产品数量吗?
发布于 2016-10-04 07:14:33
列出的函数不能返回null。唯一的返回类型是false或产品集合。
我已经搜索了代码库,而且该方法并不是存在的任何类的一部分,所以我不知道您从哪里得到的。也许是旧版本的?
若要使用扩展的最新版本为post获取相关产品,请使用以下命令:
// Get the associations helper
$associationsHelper = Mage::helper('wordpress/associations');
// Load a product collection based on $post
$products = $associationsHelper->getAssociatedProductsByPost($post);
// Get the number of products
$productCount = count($products);https://stackoverflow.com/questions/39829707
复制相似问题