Magento 在Fishpig博客中获取相关产品计数
我试图在fishpig中显示与博客相关的产品数量 我正在尝试下面的方法,但它返回空值Magento 在Fishpig博客中获取相关产品计数,magento,blogs,fishpig,Magento,Blogs,Fishpig,我试图在fishpig中显示与博客相关的产品数量 我正在尝试下面的方法,但它返回空值 $post->getAssociatedProducts(); 功能 public function getAssociatedProducts($post) { if ($post instanceof Fishpig_Wordpress_Model_Post) { $productIds = $this->_getAssociatedWpEnt
$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;
}
这会返回产品计数吗?您列出的函数不能返回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);
您列出的函数不能返回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);