/** * Retrieve product attributes as xml object * * @param Mage_Catalog_Model_Product $product * @param string $itemNodeName * @return Mage_XmlConnect_Model_Simplexml_Element */ public function productToXmlObject(Mage_Catalog_Model_Product $product, $itemNodeName = 'item') { /** @var $item Mage_XmlConnect_Model_Simplexml_Element */ $item = Mage::getModel('xmlconnect/simplexml_element', '<' . $itemNodeName . '></' . $itemNodeName . '>'); if ($product && $product->getId()) { $item->addChild('entity_id', $product->getId()); $item->addChild('name', $item->escapeXml($product->getName())); $item->addChild('entity_type', $product->getTypeId()); $item->addChild('short_description', $item->escapeXml($product->getShortDescription())); $description = Mage::helper('xmlconnect')->htmlize($item->xmlentities($product->getDescription())); $item->addChild('description', $description); $item->addChild('link', $product->getProductUrl()); if ($itemNodeName == 'item') { $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_small'); $propertyToResizeName = 'small_image'; } else { $imageToResize = Mage::helper('xmlconnect/image')->getImageSizeForContent('product_big'); $propertyToResizeName = 'image'; } $icon = clone Mage::helper('catalog/image')->init($product, $propertyToResizeName)->resize($imageToResize); $iconXml = $item->addChild('icon', $icon); $file = Mage::helper('xmlconnect')->urlToPath($icon); $iconXml->addAttribute('modification_time', filemtime($file)); $item->addChild('in_stock', (int) $product->getIsInStock()); $item->addChild('is_salable', (int) $product->isSalable()); /** * By default all products has gallery (because of collection not load gallery attribute) */ $hasGallery = 1; if ($product->getMediaGalleryImages()) { $hasGallery = sizeof($product->getMediaGalleryImages()) > 0 ? 1 : 0; } $item->addChild('has_gallery', $hasGallery); /** * If product type is grouped than it has options as its grouped items */ if ($product->getTypeId() == Mage_Catalog_Model_Product_Type_Grouped::TYPE_CODE || $product->getTypeId() == Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE) { $product->setHasOptions(true); } $item->addChild('has_options', (int) $product->getHasOptions()); if ($minSaleQty = $this->_getMinimalQty($product)) { $item->addChild('min_sale_qty', (int) $minSaleQty); } if (!$product->getRatingSummary()) { Mage::getModel('review/review')->getEntitySummary($product, Mage::app()->getStore()->getId()); } $item->addChild('rating_summary', round((int) $product->getRatingSummary()->getRatingSummary() / 10)); $item->addChild('reviews_count', $product->getRatingSummary()->getReviewsCount()); if ($this->getChild('product_price')) { $this->getChild('product_price')->setProduct($product)->setProductXmlObj($item)->collectProductPrices(); } if ($this->getChild('additional_info')) { $this->getChild('additional_info')->addAdditionalData($product, $item); } } return $item; }
/** * Returns product short description for the list view * * @param Mage_Catalog_Model_Product $p product * @return string */ public function getShortDescription($p) { if ($p->getShortDescription()) { return $p->getShortDescription(); } $pattern = Mage::getStoreConfig('ammeta/product/short_description'); $config = $this->getConfigByProduct($p); foreach ($config as $item) { if ($item->getData('short_description')) { // get first not empty pattern $pattern = $item->getData('short_description'); break; } } if ($pattern) { return $this->parse($p, $pattern); } return ''; }
public function getProductDescription() { $_helper = Mage::helper('catalog/output'); $this->item['short_description'] = $_helper->productAttribute($this->product, nl2br($this->product->getShortDescription()), 'short_description'); $this->item['short_description'] = preg_replace('/(<img[^<>]+?src\\s*=\\s*\\")([^:\\"]+\\")/i', '$1' . Mage::getBaseUrl() . '$2', $this->item['short_description']); $this->item['detail_description'] = $_helper->productAttribute($this->product, $this->product->getDescription(), 'description'); if (preg_match('/{{(.+)}}/i', $this->item['detail_description'])) { $this->item['detail_description'] = preg_replace('/(\\<img[^<>]+src\\s*=\\s*"){{(\\w+)\\s*url="(.+)}}/i', '$1' . Mage::getBaseUrl() . '/$2/$3', $this->item['detail_description']); } $this->item['detail_description'] = preg_replace('/(<img[^<>]+?src\\s*=\\s*\\")([^:\\"]+\\")/i', '$1' . Mage::getBaseUrl() . '$2', $this->item['detail_description']); $this->item['specifications'] = $this->getProductFeature(); }
/** * @param Mage_Catalog_Model_Product $product * @return array */ public function getProductData(Mage_Catalog_Model_Product $product) { $id = $product->getId(); if (!$this->helper()->shouldUseRealProductId()) { $id = $product->getSku() ? $product->getSku() : md5($id); } $data = array('id' => $id, 'url' => $product->getProductUrl(), 'name' => $product->getName(), 'unit_price' => (double) $product->getPrice(), 'unit_sale_price' => (double) $product->getFinalPrice(), 'currency' => $this->_getCurrency(), 'description' => strip_tags($product->getShortDescription()), 'sku_code' => $product->getSku()); if ($this->helper()->shouldShowProductStockInfo()) { $data['stock'] = (int) Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty(); } $catIndex = $catNames = array(); $limit = 2; $k = 0; foreach ($product->getCategoryIds() as $catId) { if (++$k > $limit) { break; } if (!isset($catIndex[$catId])) { $catIndex[$catId] = Mage::getModel('catalog/category')->load($catId); } $catNames[] = $catIndex[$catId]->getName(); } if (isset($catNames[0])) { $data['category'] = $catNames[0]; } if (isset($catNames[1])) { $data['subcategory'] = $catNames[1]; } return $data; }
/** * Get filtered product short description to be inserted into mail * * @param Mage_Catalog_Model_Product $product * @return string|null */ public function _getFilteredProductShortDescription(Mage_Catalog_Model_Product $product) { $shortDescription = $product->getShortDescription(); if ($shortDescription) { $shortDescription = Mage::getSingleton('core/input_filter_maliciousCode')->filter($shortDescription); } return $shortDescription; }
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; }
/** * @param Mage_Catalog_Model_Product $product * * @return string */ protected function _getProductDescription($product) { $description = ""; $longDescription = $product->getDescription(); $shortDescription = $product->getShortDescription(); // Convert description and/or short description with nl2br $convertDescription = Mage::helper('shopgate')->getConfig()->getConvertDescription(true); if (in_array("0", $convertDescription)) { $longDescription = nl2br($longDescription); } else { if (in_array("1", $convertDescription)) { $shortDescription = nl2br($shortDescription); } } switch (Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_DESCRIPTION_TYPE)) { case 0: $description = $longDescription; break; case 1: $description = $shortDescription; break; case 2: $description = $longDescription; $description .= "<br /><br />"; $description .= $shortDescription; break; case 3: $description = $shortDescription; $description .= "<br /><br />"; $description .= $longDescription; break; case 4: $descriptionAttribute = Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_DESCRIPTION_ATTR_CODE); $attributeCodes = explode(",", $descriptionAttribute); $counter = 0; foreach ($attributeCodes as $attributeCode) { $attributeCode = trim($attributeCode); if (!empty($attributeCode)) { /** @var Mage_Catalog_Model_Resource_Eav_Attribute $attribute */ $attribute = $product->getResource()->getAttribute($attributeCode); $values = explode(',', $attribute->getFrontend()->getValue($product)); $description1 = implode('<br />', $values); if (in_array("2", $convertDescription)) { $description1 = nl2br($description1); } if (!empty($description1) && $counter > 0) { $description .= "<br /><br />"; } $description .= $description1; } $counter++; } } return $description; }
/** * 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; }
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; }