Example #1
0
 /**
  * Prepare category attribute html output
  *
  * @param   Mage_Catalog_Model_Category $category
  * @param   string $attributeHtml
  * @param   string $attributeName
  * @return  string
  */
 public function categoryAttribute($category, $attributeHtml, $attributeName)
 {
     $isDefaultCategory = $category->getId() == Mage::app()->getStore()->getRootCategoryId();
     if ($attributeName == 'name' && $isDefaultCategory) {
         /** @var Amasty_Shopby_Helper_Attributes $helper */
         $helper = Mage::helper('amshopby/attributes');
         $setting = $helper->getRequestedBrandOption();
         if (is_array($setting)) {
             return $this->escapeHtml($setting['title']);
         }
     }
     return parent::categoryAttribute($category, $attributeHtml, $attributeName);
 }
Example #2
0
 public function productAttribute($product, $attributeHtml, $attributeName)
 {
     //	if ($attributeName!='short_description') {
     //		return parent::productAttribute($product, $attributeHtml, $attributeName);
     //	}
     $magentoCurrentUrl = Mage::helper('core/url')->getCurrentUrl();
     $_prod = Mage::getModel('catalog/product')->load($product->getId());
     if (!$_prod->getData('is_product_gift_enabled')) {
         return parent::productAttribute($product, $attributeHtml, $attributeName);
     }
     if (!$product->getUrlPath()) {
         return parent::productAttribute($product, $attributeHtml, $attributeName);
         //$html=Mage::helper('productgift')->getBlockGiftCategory($_prod->getData('sku_of_product_gift'));
     } else {
         $html = Mage::helper('productgift')->getBlockGift($_prod->getData('sku_of_product_gift'));
     }
     return '<div>' . parent::productAttribute($product, $attributeHtml, $attributeName) . '</div>' . $html;
 }
Example #3
0
 public function testProcess()
 {
     $this->_helper->addHandler('sampleProcessor', $this);
     $this->assertStringStartsWith(__CLASS__, $this->_helper->process('sampleProcessor', uniqid(), array()));
 }
Example #4
0
 /**
  * @param Mage_Catalog_Model_Product $product
  * @param array $additionalAttributes
  * @return array
  */
 public function getProductData(Mage_Catalog_Model_Product $product, $additionalAttributes = array())
 {
     $product_data = array();
     $attributes = array_merge((array) $this->config->attributes, $additionalAttributes);
     // store
     $store = Mage::getModel('core/store')->load($product->getStoreId());
     foreach ($attributes as $attribute) {
         if ($attribute->type == 'constant') {
             $value = $attribute->value;
         } elseif ($attribute->type == 'product_attribute') {
             // if this is a normal product attribute, retrieve it's frontend
             // representation, or the default value if it doesn't have a value
             // for this attribute
             if ($product->getData($attribute->magento) === null) {
                 if (isset($attribute->default)) {
                     $value = $attribute->default;
                 } else {
                     $value = '';
                 }
             } else {
                 /** @var $attributeObj Mage_Catalog_Model_Resource_Eav_Attribute */
                 $attributeObj = $product->getResource()->getAttribute($attribute->magento);
                 $value = $attributeObj->getFrontend()->getValue($product);
                 // The output helper performs this check as well, but we don't want to unnecessarily send off
                 // every single attribute to this helper if we can avoid it.
                 if ($attributeObj->getIsWysiwygEnabled()) {
                     $value = $this->catalogOutputHelper->productAttribute($product, $value, $attribute->magento);
                 }
             }
         } elseif ($attribute->type == 'stock_attribute') {
             $value = $product->getStockItem()->getData($attribute->magento);
             if ($value === null) {
                 if (isset($attribute->default)) {
                     $value = $attribute->default;
                 } else {
                     $value = '';
                 }
             }
         } elseif ($attribute->type == 'computed') {
             // if this is a computed attribute, handle it depending on its code
             switch ($attribute->magento) {
                 case 'final_price':
                     $price = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true);
                     $value = sprintf('%.2f', (double) $store->convertPrice($price, false, false));
                     $value .= ' ' . Mage::getStoreConfig('currency/options/default', $product->getStoreId());
                     break;
                 case 'special_price':
                     $price = Mage::helper('tax')->getPrice($product, $product->getSpecialPrice(), true);
                     $value = sprintf('%.2f', (double) $store->convertPrice($price, false, false));
                     $value .= ' ' . Mage::getStoreConfig('currency/options/default', $product->getStoreId());
                     break;
                 case 'price':
                     $price = Mage::helper('tax')->getPrice($product, $product->getFinalPrice(), true);
                     $value = sprintf('%.2f', (double) $store->convertPrice($price, false, false));
                     $value .= ' ' . Mage::getStoreConfig('currency/options/default', $product->getStoreId());
                     break;
                 case 'product_link':
                     $value = $this->getCleanProductUrl($product);
                     break;
                 case 'image_url':
                     $value = (string) Mage::helper('catalog/image')->init($product, 'image');
                     break;
                 case 'instock_y_n':
                     $value = $product->isSaleable() ? "Y" : "N";
                     // myshopping
                     break;
                 case 'availability_yes_no':
                     $value = $product->isSaleable() ? "yes" : "no";
                     break;
                 case 'availability_google':
                     $value = $product->isSaleable() ? 'in stock' : 'out of stock';
                     break;
                 case 'currency':
                     $value = Mage::getStoreConfig('mehulchaudhari_feedsgenerator/' . $this->config->config_path . '/currency');
                     break;
                 case 'google_taxonomy':
                     if (!isset($attribute->exclude_cats)) {
                         $attribute->exclude_cats = array();
                     }
                     $categoryIds = $this->getCategoryPathIds($product, $attribute->exclude_cats);
                     if (count($categoryIds) > 0) {
                         $categoryId = $categoryIds[count($categoryIds) - 1];
                         $category = Mage::getModel('catalog/category')->load($categoryId);
                         $value = $category->getResource()->getAttribute('google_product_category')->getFrontend()->getValue($category);
                     } else {
                         $value = '';
                     }
                     break;
                 case 'category_path':
                 case 'category_last':
                     if (!isset($attribute->exclude_cats)) {
                         $attribute->exclude_cats = array();
                     }
                     $value = $this->getCategoryPath($product, $attribute->exclude_cats);
                     if ($attribute->magento == 'category_last') {
                         if (count($value) > 0) {
                             $value = $value[count($value) - 1];
                         } else {
                             $value = utf8_encode(Mage::getStoreConfig('mehulchaudhari_feedsgenerator/' . $this->config->config_path . '/defaultcategory'));
                         }
                     }
                     break;
                 case 'child_skus':
                     $value = array();
                     if ($product->getTypeId() == 'configurable') {
                         foreach ($product->getTypeInstance()->getUsedProducts() as $child) {
                             $value[] = $child->getSku();
                         }
                     }
                     break;
                 default:
                     $this->log("Unknown computed attribute code: {$attribute->magento}");
                     $value = 'UNKNOWN_COMPUTED_ATTRIBUTE_CODE';
             }
         } else {
             $this->log("Unknown attribute type: {$attribute->type}");
             $value = 'UNKNOWN_ATTRIBUTE_TYPE';
         }
         // Clean up the value, or each of its elements if it's an array
         if (is_array($value)) {
             foreach ($value as &$element) {
                 $element = $this->cleanValue($attribute, $element);
             }
             unset($element);
         } else {
             $value = $this->cleanValue($attribute, $value);
         }
         $product_data[$attribute->feed] = $value;
     }
     return $product_data;
 }