/** * Retrieve a collection of products assocaited with the post * * @param Fishpig_Wordpress_Model_Post $post * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ public function getAssociatedProductsByPost(Fishpig_Wordpress_Model_Post $post) { if (!$this->isConnected() || !$post instanceof Fishpig_Wordpress_Model_Post) { return false; } $associations = array_keys($this->getReverseAssociations('product/post', $post->getId())); foreach ($post->getParentCategories() as $category) { $associations = array_merge($associations, array_keys($this->getReverseAssociations('product/category', $category->getId()))); } $associations = array_unique($associations); if (count($associations) > 0) { $collection = Mage::getResourceModel('catalog/product_collection'); Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); if (!Mage::getStoreConfigFlag('cataloginventory/options/show_out_of_stock')) { Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection); } $collection->addAttributeToFilter('status', 1); $collection->addAttributeToFilter('entity_id', array('in' => $associations)); return $collection; } return false; }
/** * Retrieve a collection of products assocaited with the post * * @param Fishpig_Wordpress_Model_Post $post * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection */ 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; }