Estou tentando exibir a contagem de produtos que está associada a um blog no fishpig.
Estou tentando o método abaixo, mas está retornando um valor nulo.
$post->getAssociatedProducts();
Função
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;
}
Isso retornará a contagem do produto?
A função listada não pode retornar nula. Os únicos tipos de retorno são falsos ou uma coleção de produtos.
Eu pesquisei a base do código e esse método não faz parte de nenhuma classe existente, então não tenho certeza de onde você o obteve. Talvez seja de uma versão antiga?
Para obter os produtos associados para uma postagem usando a versão mais recente da extensão, você usaria o seguinte:
// 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);
Este artigo é coletado da Internet.
Se houver alguma infração, entre em [email protected] Delete.
deixe-me dizer algumas palavras