Exemple #1
0
 /**
  * Returns the state of this offer.  Since we only ever send events for published offers this will be hardcoded.
  * @return string
  */
 protected function _createState()
 {
     $status = $this->_product->isInStock() ? 'PUBLISHED' : 'SUSPENDED';
     if (!$this->_product->isVisibleInSiteVisibility()) {
         $status = 'SUSPENDED';
     }
     if (!Mage::app()->getStore($this->_storeId)->getIsActive()) {
         $status = 'SUSPENDED';
     }
     return $status;
 }
 public function isVisibleInSiteVisibility()
 {
     #Force visible any simple products which have a parent conf product.
     #this will only apply to products which have been added to the cart
     if (is_callable(array($this->getTypeInstance(), 'hasConfigurableProductParentId')) && $this->getTypeInstance()->hasConfigurableProductParentId()) {
         return true;
     } else {
         return parent::isVisibleInSiteVisibility();
     }
 }
Exemple #3
0
 /**
  * @covers Mage_Catalog_Model_Product::getVisibleInCatalogStatuses
  * @covers Mage_Catalog_Model_Product::getVisibleStatuses
  * @covers Mage_Catalog_Model_Product::isVisibleInCatalog
  * @covers Mage_Catalog_Model_Product::getVisibleInSiteVisibilities
  * @covers Mage_Catalog_Model_Product::isVisibleInSiteVisibility
  */
 public function testVisibilityApi()
 {
     $this->assertEquals(array(Mage_Catalog_Model_Product_Status::STATUS_ENABLED), $this->_model->getVisibleInCatalogStatuses());
     $this->assertEquals(array(Mage_Catalog_Model_Product_Status::STATUS_ENABLED), $this->_model->getVisibleStatuses());
     $this->_model->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
     $this->assertFalse($this->_model->isVisibleInCatalog());
     $this->_model->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
     $this->assertTrue($this->_model->isVisibleInCatalog());
     $this->assertEquals(array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH), $this->_model->getVisibleInSiteVisibilities());
     $this->assertFalse($this->_model->isVisibleInSiteVisibility());
     $this->_model->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH);
     $this->assertTrue($this->_model->isVisibleInSiteVisibility());
     $this->_model->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG);
     $this->assertTrue($this->_model->isVisibleInSiteVisibility());
     $this->_model->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
     $this->assertTrue($this->_model->isVisibleInSiteVisibility());
 }
 public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true)
 {
     $result = array();
     $result['entity_id'] = $product->getEntityId();
     $result['sku'] = $product->getSku();
     $result['name'] = $product->getName();
     $result['price'] = $product->getPrice();
     $result['special_price'] = $product->getSpecialPrice();
     $result['special_from_date'] = $product->getSpecialFromDate();
     $result['special_to_date'] = $product->getSpecialToDate();
     $result['cost'] = $product->getCost();
     $result['description'] = $product->getDescription();
     $result['short_description'] = $product->getShortDescription();
     $result['weight'] = $product->getWeight();
     if ($product->isVisibleInSiteVisibility()) {
         $result['url_path'] = $this->_getProductUrlWithCache($product);
     }
     $parentProduct = $this->_getParentProduct($product);
     if ($parentProduct != null) {
         $result['parent_id'] = $parentProduct->getEntityId();
         $result['parent_sku'] = $parentProduct->getSku();
         if (!$product->isVisibleInSiteVisibility()) {
             $result['name'] = $parentProduct->getName();
             if ($parentProduct->isVisibleInSiteVisibility()) {
                 $result['url_path'] = $this->_getProductUrlWithCache($parentProduct);
             }
         }
         if ($includeExtras && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parentProduct->getTypeId()) {
             $result['purchasable'] = $this->_isPurchasable($product, $parentProduct);
             $attributes = $parentProduct->getTypeInstance(true)->getUsedProductAttributes($parentProduct);
             $freshProduct = null;
             foreach ($attributes as $attribute) {
                 if (!array_key_exists('configurable_attributes', $result)) {
                     $result['configurable_attributes'] = array();
                 }
                 $attr = array();
                 $attr['attribute_name'] = $attribute->getFrontend()->getLabel();
                 $attr['value'] = $product->getAttributeText($attribute->getAttributeCode());
                 if (empty($attr['value'])) {
                     // use the EAV tables only if the flat table doesn't work
                     if ($freshProduct == null) {
                         $freshProduct = Mage::getModel('catalog/product')->load($product->getEntityId());
                     }
                     $attr['value'] = $attribute->getFrontend()->getValue($freshProduct);
                 }
                 $result['configurable_attributes'][] = $attr;
             }
         }
     }
     if (!isset($result['purchasable'])) {
         $result['purchasable'] = $this->_isPurchasable($product);
     }
     $images = $this->_getProductImages($product);
     if (isset($images['image'])) {
         $result['image'] = $images['image'];
     }
     if (isset($images['small_image'])) {
         $result['small_image'] = $images['small_image'];
     }
     if (isset($images['thumbnail'])) {
         $result['thumbnail'] = $images['thumbnail'];
     }
     if ($includeExtras) {
         // Metas
         $metas = $this->_getMetas($storeId, $product, $parentProduct);
         if ($metas != null) {
             //if(isset($metas['meta1'])) $result['meta1'] = $metas['meta1'];
             //if(isset($metas['meta2'])) $result['meta2'] = $metas['meta2'];
             //if(isset($metas['meta3'])) $result['meta3'] = $metas['meta3'];
             //if(isset($metas['meta4'])) $result['meta4'] = $metas['meta4'];
             if (isset($metas['meta5'])) {
                 $result['meta5'] = $metas['meta5'];
             }
         }
         //Custom For ST Bernard Sports
         // Set IsNew Flag if product is less then 45 days old.
         $result['meta4'] = strtotime($product->getCreatedAt()) + 45 * 24 * 60 * 60 < time() ? "False" : "True";
         // Brand and Category
         $brandAndCategoryProduct = !$parentProduct || $product->isVisibleInSiteVisibility() ? $product : $parentProduct;
         $setSettings = $this->_getProductAttributeSetSettings($brandAndCategoryProduct);
         if ($setSettings['brandAttribute'] != null) {
             $result['brand'] = $brandAndCategoryProduct->getAttributeText($setSettings['brandAttribute']);
         }
         if ($setSettings['catFromMagento']) {
             $cats = $this->_getCategoryInformation($storeId, $brandAndCategoryProduct);
             if (isset($cats['category'])) {
                 $result['category'] = $cats['category'];
             }
             if (isset($cats['sub_category'])) {
                 $result['sub_category'] = $cats['sub_category'];
             }
             //Custom For ST Bernard Sports
             if (isset($cats['third_category'])) {
                 $result['meta3'] = $cats['third_category'];
             }
         } else {
             if ($setSettings['catFromAttributes']) {
                 if ($setSettings['categoryAttribute'] != null) {
                     $result['category'] = $brandAndCategoryProduct->getAttributeText($setSettings['categoryAttribute']);
                 }
                 if ($setSettings['subcategoryAttribute'] != null) {
                     $result['sub_category'] = $brandAndCategoryProduct->getAttributeText($setSettings['subcategoryAttribute']);
                 }
             }
         }
         // Inventory
         $result['in_stock'] = $product->isAvailable() ? "true" : "false";
         $stockItem = $product->getStockItem();
         if ($stockItem) {
             $result['qty_on_hand'] = $stockItem->getStockQty();
         }
         // Related Products
         $result['links'] = $this->_getProductLinks($product);
     }
     $result['type'] = $product->getTypeId();
     return $result;
 }
 /**
  * Inflate an API object from a product object
  *
  * @param Mage_Catalog_Model_Product $product       Product
  * @param int                        $storeId       Magento store ID
  * @param bool                       $includeExtras Retrieve all information
  *
  * @return array
  */
 public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true)
 {
     $result = array();
     $result['entity_id'] = $product->getEntityId();
     $result['sku'] = $product->getSku();
     $result['name'] = $product->getName();
     $result['price'] = $product->getPrice();
     $result['special_price'] = $product->getSpecialPrice();
     $result['special_from_date'] = $product->getSpecialFromDate();
     $result['special_to_date'] = $product->getSpecialToDate();
     $result['cost'] = $product->getCost();
     $result['description'] = $product->getDescription();
     $result['short_description'] = $product->getShortDescription();
     $result['weight'] = $product->getWeight();
     if ($product->isVisibleInSiteVisibility()) {
         $result['url_path'] = $this->_getProductUrlWithCache($product);
     }
     $parentProduct = $this->_getParentProduct($product);
     if ($parentProduct != null) {
         $result['parent_id'] = $parentProduct->getEntityId();
         $result['parent_sku'] = $parentProduct->getSku();
         if (!$product->isVisibleInSiteVisibility()) {
             $result['name'] = $parentProduct->getName();
             if ($parentProduct->isVisibleInSiteVisibility()) {
                 $result['url_path'] = $this->_getProductUrlWithCache($parentProduct);
             }
         }
         if ($includeExtras && $this->_isConfigurableProduct($parentProduct)) {
             $result['purchasable'] = $this->_isPurchasable($product, $parentProduct);
             /* @var Mage_Catalog_Model_Product_Type_Configurable $typeInst */
             $typeInst = $parentProduct->getTypeInstance(true);
             $attributes = $typeInst->getUsedProductAttributes($parentProduct);
             /* @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute */
             foreach ($attributes as $attribute) {
                 if (!array_key_exists('configurable_attributes', $result)) {
                     $result['configurable_attributes'] = array();
                 }
                 $result['configurable_attributes'][] = array('attribute_name' => $attribute->getAttributeCode());
             }
         }
     }
     if (!isset($result['purchasable'])) {
         $result['purchasable'] = $this->_isPurchasable($product);
     }
     $images = $this->_getProductImages($product);
     if (isset($images['image'])) {
         $result['image'] = $images['image'];
     }
     if (isset($images['small_image'])) {
         $result['small_image'] = $images['small_image'];
     }
     if (isset($images['thumbnail'])) {
         $result['thumbnail'] = $images['thumbnail'];
     }
     if ($includeExtras) {
         $metas = $this->_getMetas($storeId, $product, $parentProduct);
         if ($metas != null) {
             /*if (isset($metas['meta3'])) {
                   $result['meta3'] = $metas['meta3'];
               }*/
             if (isset($metas['meta4'])) {
                 $result['meta4'] = $metas['meta4'];
             }
             if (isset($metas['meta5'])) {
                 $result['meta5'] = $metas['meta5'];
             }
         }
         //Custom for Sportys
         $stores = array();
         foreach ($product->getStoreIds() as $storeID) {
             $store = Mage::getModel('core/store')->load($storeID);
             $stores[] = $store->getCode();
         }
         $result["meta3"] = implode(',', $stores);
         // Brand and Category
         $brandCatProduct = $product;
         if ($parentProduct && !$product->isVisibleInSiteVisibility()) {
             $brandCatProduct = $parentProduct;
         }
         $setSettings = $this->_getProductAttributeSetSettings($brandCatProduct);
         if ($setSettings['brandAttribute'] != null) {
             $result['brand'] = $this->_getProductAttribute($brandCatProduct, $setSettings['brandAttribute']);
         }
         if ($setSettings['catFromMagento']) {
             $cats = $this->_getCategoryInformation($storeId, $brandCatProduct);
             if (isset($cats['category'])) {
                 $result['category'] = $cats['category'];
             }
             if (isset($cats['sub_category'])) {
                 $result['sub_category'] = $cats['sub_category'];
             }
         } else {
             if ($setSettings['catFromAttributes']) {
                 if ($setSettings['categoryAttribute'] != null) {
                     $result['category'] = $this->_getProductAttribute($brandCatProduct, $setSettings['categoryAttribute']);
                 }
                 if ($setSettings['subcategoryAttribute'] != null) {
                     $result['sub_category'] = $this->_getProductAttribute($brandCatProduct, $setSettings['subcategoryAttribute']);
                 }
             }
         }
         $result['attributes'] = $this->_getProductAttributes($product);
         // Inventory
         $result['in_stock'] = $product->isAvailable() ? "true" : "false";
         /* @var Mage_Cataloginventory_Model_Stock_Item $stockItem */
         $stockItem = $product->getStockItem();
         if ($stockItem) {
             $result['qty_on_hand'] = $stockItem->getStockQty();
         }
         // Related Products
         $result['links'] = $this->_getProductLinks($product);
     }
     $result['type'] = $product->getTypeId();
     return $result;
 }
Exemple #6
0
 /**
  * Retrieve Item Store for URL
  *
  * @param Mage_Catalog_Model_Product|Mage_Wishlist_Model_Item $item
  * @return Mage_Core_Model_Store
  */
 protected function _getUrlStore($item)
 {
     $storeId = null;
     if ($item instanceof Mage_Catalog_Model_Product) {
         if ($item->isVisibleInSiteVisibility()) {
             $storeId = $item->getStoreId();
         } else {
             if ($item->hasUrlDataObject()) {
                 $storeId = $item->getUrlDataObject()->getStoreId();
             }
         }
     }
     return Mage::app()->getStore($storeId);
 }
 /**
  * Builds the availability for the product.
  *
  * @param Mage_Catalog_Model_Product $product the product model.
  *
  * @return string
  */
 protected function buildAvailability(Mage_Catalog_Model_Product $product)
 {
     $availability = self::OUT_OF_STOCK;
     if (!$product->isVisibleInSiteVisibility()) {
         $availability = self::INVISIBLE;
     } elseif ($product->isAvailable()) {
         $availability = self::IN_STOCK;
     }
     return $availability;
 }
 public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true)
 {
     $result = array();
     $result['entity_id'] = $product->getEntityId();
     $result['sku'] = $product->getSku();
     $result['name'] = $product->getName();
     $result['price'] = $product->getPrice();
     $result['special_price'] = $product->getSpecialPrice();
     $result['special_from_date'] = $product->getSpecialFromDate();
     $result['special_to_date'] = $product->getSpecialToDate();
     $result['cost'] = $product->getCost();
     $result['description'] = $product->getDescription();
     $result['short_description'] = $product->getShortDescription();
     $result['weight'] = $product->getWeight();
     if ($product->isVisibleInSiteVisibility()) {
         $prodUrlStr = $product->getProductUrl();
         $prodUrl = Mage::getSingleton('core/url')->parseUrl($prodUrlStr);
         $result['url_path'] = substr($prodUrl->getPath(), 1);
     }
     $parentProduct = $this->_getParentProduct($product);
     if ($parentProduct != null) {
         $result['parent_id'] = $parentProduct->getEntityId();
         $result['parent_sku'] = $parentProduct->getSku();
         if (!$product->isVisibleInSiteVisibility()) {
             $result['name'] = $parentProduct->getName();
             if ($parentProduct->isVisibleInSiteVisibility()) {
                 $prodUrlStr = $parentProduct->getProductUrl();
                 $prodUrl = Mage::getSingleton('core/url')->parseUrl($prodUrlStr);
                 $result['url_path'] = substr($prodUrl->getPath(), 1);
             }
         }
         if ($includeExtras && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parentProduct->getTypeId()) {
             $result['purchasable'] = $this->_isPurchasable($product, $parentProduct);
             $attributes = $parentProduct->getTypeInstance(true)->getUsedProductAttributes($parentProduct);
             foreach ($attributes as $attribute) {
                 if (!array_key_exists('configurable_attributes', $result)) {
                     $result['configurable_attributes'] = array();
                 }
                 $attr = array();
                 $attr['attribute_name'] = $attribute->getFrontend()->getLabel();
                 $attr['value'] = $product->getAttributeText($attribute->getAttributeCode());
                 $result['configurable_attributes'][] = $attr;
             }
         }
     }
     if (!isset($result['purchasable'])) {
         $result['purchasable'] = $this->_isPurchasable($product);
     }
     $images = $this->_getProductImages($product);
     if (isset($images['image'])) {
         $result['image'] = $images['image'];
     }
     if (isset($images['small_image'])) {
         $result['small_image'] = $images['small_image'];
     }
     if (isset($images['thumbnail'])) {
         $result['thumbnail'] = $images['thumbnail'];
     }
     if ($includeExtras) {
         // Metas
         $metas = $this->_getMetas($storeId, $product, $parentProduct);
         if ($metas != null) {
             //if(isset($metas['meta1'])) $result['meta1'] = $metas['meta1'];
             //if(isset($metas['meta2'])) $result['meta2'] = $metas['meta2'];
             if (isset($metas['meta3'])) {
                 $result['meta3'] = $metas['meta3'];
             }
             if (isset($metas['meta4'])) {
                 $result['meta4'] = $metas['meta4'];
             }
             if (isset($metas['meta5'])) {
                 $result['meta5'] = $metas['meta5'];
             }
         }
         // Brand and Category
         $brandAndCategoryProduct = !$parentProduct || $product->isVisibleInSiteVisibility() ? $product : $parentProduct;
         $setSettings = $this->_getProductAttributeSetSettings($brandAndCategoryProduct);
         if ($setSettings['brandAttribute'] != null) {
             $result['brand'] = $brandAndCategoryProduct->getAttributeText($setSettings['brandAttribute']);
         }
         if ($setSettings['catFromMagento']) {
             $cats = $this->_getCategoryInformation($storeId, $brandAndCategoryProduct);
             if (isset($cats['category'])) {
                 $result['category'] = $cats['category'];
             }
             if (isset($cats['sub_category'])) {
                 $result['sub_category'] = $cats['sub_category'];
             }
         } else {
             if ($setSettings['catFromAttributes']) {
                 if ($setSettings['categoryAttribute'] != null) {
                     $result['category'] = $brandAndCategoryProduct->getAttributeText($setSettings['categoryAttribute']);
                 }
                 if ($setSettings['subcategoryAttribute'] != null) {
                     $result['sub_category'] = $brandAndCategoryProduct->getAttributeText($setSettings['subcategoryAttribute']);
                 }
             }
         }
         // Inventory
         $result['in_stock'] = $product->isAvailable() ? "true" : "false";
         $stockItem = $product->getStockItem();
         if ($stockItem) {
             $result['qty_on_hand'] = $stockItem->getStockQty();
         }
         // Related Products
         $result['links'] = $this->_getProductLinks($product);
     }
     $result['type'] = $product->getTypeId();
     return $result;
 }