Esempio n. 1
0
 /** 
  * 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_Abstract $post)
 {
     if (!$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);
         $collection->addAttributeToFilter('status', 1);
         $collection->addAttributeToFilter('entity_id', array('in' => $associations));
         return $collection;
     }
     return false;
 }
 /**
  * Retrieve the featured image for the post
  *
  * @param Fishpig_Wordpress_Model_Post_Abstract $post
  * @return Fishpig_Wordpress_Model_Image $image
  */
 public function getFeaturedImage(Fishpig_Wordpress_Model_Post_Abstract $post)
 {
     if ($images = $post->getImages()) {
         $select = $this->_getReadAdapter()->select()->from($this->getTable('wordpress/post_meta'), 'meta_value')->where('post_id=?', $post->getId())->where('meta_key=?', '_thumbnail_id')->limit(1);
         if (($imageId = $this->_getReadAdapter()->fetchOne($select)) !== false) {
             if (preg_match('/([a-z-]{1,})([0-9]{1,})/', $imageId, $matches)) {
                 if (($prefix = trim($matches[1], '- ')) !== '') {
                     $eventData = array('object' => $post, 'image_id' => $matches[2], 'original_image_id' => $imageId, 'result' => new Varien_Object());
                     Mage::dispatchEvent('wordpress_post_get_featured_image_' . $prefix, $eventData);
                     if ($eventData['result']->getFeaturedImage()) {
                         return $eventData['result']->getFeaturedImage();
                     }
                 }
             } else {
                 return Mage::getModel('wordpress/image')->load($imageId);
             }
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * Retrieve the featured image for the post
  *
  * @param Fishpig_Wordpress_Model_Post_Abstract $post
  * @return Fishpig_Wordpress_Model_Image $image
  */
 public function getFeaturedImage(Fishpig_Wordpress_Model_Post_Abstract $post)
 {
     if ($images = $post->getImages()) {
         $select = $this->_getReadAdapter()->select()->from(Mage::helper('wordpress/db')->getTableName('postmeta'), 'meta_value')->where('post_id=?', $post->getId())->where('meta_key=?', '_thumbnail_id')->limit(1);
         if ($featuredImageId = $this->_getReadAdapter()->fetchOne($select)) {
             return Mage::getModel('wordpress/image')->load($featuredImageId);
         }
     }
 }