/** * Check if product is configurable * * @param Mage_Catalog_Model_Product $product * @return bool */ public function canConfigure($product = null) { if (isset($product->getAttributes()['adyen_subscription_type'])) { if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) { return true; } } return false; }
public function testGetAttributes() { // fixture required $this->_model->load(1); $attributes = $this->_model->getAttributes(); $this->assertArrayHasKey('name', $attributes); $this->assertArrayHasKey('sku', $attributes); $this->assertInstanceOf('Mage_Catalog_Model_Resource_Eav_Attribute', $attributes['sku']); }
/** * Return Product attribute by attribute's ID * * @param Mage_Catalog_Model_Product $product * @param int $attributeId * @return null|Mage_Catalog_Model_Entity_Attribute Product's attribute */ public function getProductAttribute(Mage_Catalog_Model_Product $product, $attributeId) { if (!isset($this->_productAttributes[$product->getId()])) { $attributes = $product->getAttributes(); foreach ($attributes as $attribute) { $this->_productAttributes[$product->getId()][$attribute->getAttributeId()] = $attribute; } } return isset($this->_productAttributes[$product->getId()][$attributeId]) ? $this->_productAttributes[$product->getId()][$attributeId] : null; }
public function getAttributes($groupId = null, $skipSuper = false) { $attributes = parent::getAttributes($groupId, $skipSuper); foreach ($attributes as $k => $attr) { if ($attr->getAttributeCode() == 'downloads_title') { unset($attributes[$k]); break; } } return $attributes; }
/** * @param Mage_Catalog_Model_Product $product */ protected function _attributes(Mage_Catalog_Model_Product &$product) { $_attributes = $product->getAttributes(); /** @var Mage_Eav_Model_Entity_Attribute $attribute */ foreach ($_attributes as $attribute) { if ($attribute->getBackendType() == self::ATTRIBUTE_TYPE_TO_PREPARE) { $attributeText = $product->getAttributeText($attribute->getAttributeCode()); //getting attribute value $product->setData($attribute->getAttributeCode(), $attributeText); //setting this to product (override existing integer value) } } }
/** * set properties */ public function setProperties() { if (empty($this->_ignoredProductAttributeCodes)) { $ignoredProductAttributeCodes = array("manufacturer", "model"); $ignoredProperties = explode(",", Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_FILTER_PROPERTIES)); $ignoredProductAttributeCodes = array_merge($ignoredProductAttributeCodes, $ignoredProperties); $this->_ignoredProductAttributeCodes = array_unique($ignoredProductAttributeCodes); } if (empty($this->_forcedProductAttributeCodes)) { $forcedProperties = explode(",", Mage::getStoreConfig(Shopgate_Framework_Model_Config::XML_PATH_SHOPGATE_EXPORT_FORCE_PROPERTY_EXPORT)); $this->_forcedProductAttributeCodes = array_unique($forcedProperties); } $result = array(); $cacheKey = 'product_type_' . $this->item->getTypeId() . '_attributes_' . $this->item->getAttributeSetId(); $cache = Mage::app()->getCacheInstance(); $value = $cache->load($cacheKey); if ($value !== false) { $attributes = unserialize($value); } else { $attributes = $this->item->getAttributes(); $attrCache = array(); foreach ($attributes as $attribute) { $code = $attribute->getAttributeCode(); /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ if ($attribute && $attribute->getIsVisibleOnFront() || in_array($code, $this->_forcedProductAttributeCodes)) { if (in_array($code, $this->_ignoredProductAttributeCodes) && !in_array($code, $this->_forcedProductAttributeCodes)) { continue; } $attrCache[$code] = array('id' => $attribute->getId(), 'label' => $attribute->getStoreLabel($this->_getConfig()->getStoreViewId())); } } $attributes = $attrCache; $cache->save(serialize($attrCache), $cacheKey, array('shopgate_export', Mage_Core_Model_Mysql4_Collection_Abstract::CACHE_TAG, Mage_Catalog_Model_Resource_Eav_Attribute::CACHE_TAG), 60); } foreach ($attributes as $code => $data) { $value = $this->item->getResource()->getAttribute($code)->getFrontend()->getValue($this->item); if (!empty($value) && !is_array($value)) { $propertyItemObject = new Shopgate_Model_Catalog_Property(); $propertyItemObject->setUid($data['id']); $propertyItemObject->setLabel($data['label']); $propertyItemObject->setValue($value); $result[] = $propertyItemObject; } } parent::setProperties($result); }
/** * Retrieve product subscription, if product is a subscription, else false * * @param Mage_Catalog_Model_Product $product * @return Adyen_Subscription_Model_Product_Subscription|false */ public function getProductSubscription($product) { if (isset($product->getAttributes()['adyen_subscription_type'])) { if ($product->getData('adyen_subscription_type') != Adyen_Subscription_Model_Product_Subscription::TYPE_DISABLED) { $option = $product->getCustomOption('additional_options'); if ($option) { $additionalOptions = unserialize($option->getValue()); foreach ($additionalOptions as $additional) { if ($additional['code'] == 'adyen_subscription') { if ($additional['option_value'] != 'none') { $subscription = Mage::getModel('adyen_subscription/product_subscription')->load($additional['option_value']); if (!$subscription->getId()) { return false; } return $subscription; } } } } } } return false; }
/** * Fetches attributes for properties column and filters by ignored attributes. * * @param Mage_Catalog_Model_Product $product * @param $ignoredProductAttributeCodes * @param array $forcedProductAttributeCodes * * @return array */ protected function _getProductProperties($product, $ignoredProductAttributeCodes, $forcedProductAttributeCodes = array()) { $properties = array(); $cacheKey = 'product_type_' . $product->getTypeId() . '_attributes_' . $product->getAttributeSetId(); $cache = Mage::app()->getCacheInstance(); $value = $cache->load($cacheKey); if ($value !== false) { $attributes = unserialize($value); } else { $attributes = $product->getAttributes(); $attrCache = array(); foreach ($attributes as $attribute) { $code = $attribute->getAttributeCode(); $isFilterable = Mage::getStoreConfigFlag('shopgate/export/filterable_attributes') ? $attribute->getIsFilterable() : false; /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ if ($attribute && ($attribute->getIsVisibleOnFront() || $isFilterable || in_array($code, $forcedProductAttributeCodes))) { if (in_array($code, $ignoredProductAttributeCodes) && !in_array($code, $forcedProductAttributeCodes)) { continue; } $attrCache[$code] = array('id' => $attribute->getId(), 'label' => $attribute->getStoreLabel($this->_getConfig()->getStoreViewId())); } } $attributes = $attrCache; $cache->save(serialize($attrCache), $cacheKey, array('shopgate_export', Mage_Core_Model_Mysql4_Collection_Abstract::CACHE_TAG, Mage_Catalog_Model_Resource_Eav_Attribute::CACHE_TAG), 3600); } foreach ($attributes as $code => $data) { $value = $product->getResource()->getAttribute($code)->getFrontend()->getValue($product); if ($value) { $properties[$code] = "{$data['label']}=>{$value}"; } } return $properties; }
/** * Searches for all media_image type attributes for this product's attribute set, and creates a hash matching * the attribute code to its value, which is a media path. The attribute code is used as the * image 'view', and we use array_search to match based on media path. * @param Mage_Catalog_Model_Product $mageProduct * @return array of view_names => image_paths */ protected function _getMageImageViewMap(Mage_Catalog_Model_Product $mageProduct) { $attributes = $mageProduct->getAttributes(); return array_reduce(array_keys($attributes), function ($result = [], $key) use($attributes, $mageProduct) { if (!strcmp($attributes[$key]->getFrontendInput(), EbayEnterprise_ProductImageExport_Model_Image_Export::FRONTEND_INPUT)) { $result[$key] = $mageProduct->getData($key); } return $result; }); }
protected function checkProductAttributesRequired(Mage_Catalog_Model_Product $product) { $haystack = $product->getAttributes(); $target = array(Lema21_Nfe_Model_TransformToXML::ATTR_CODIGO_NCM, Lema21_Nfe_Model_TransformToXML::ATTR_CODIGO_ORIGEM, Lema21_Nfe_Model_TransformToXML::ATTR_OPERATION_NAME, Lema21_Nfe_Model_TransformToXML::ATTR_OPERATION_UNIT); if (count(array_intersect($haystack, $target)) == count($target)) { return true; } return false; }
/** * Catalog product initialize after loading * * @param Mage_Catalog_Model_Product $model * @return void */ public function catalogProductLoadAfter($model) { if (!$model->getId()) { return; } if (!$this->_role->hasWebsiteAccess($model->getWebsiteIds())) { $this->_throwLoad(); } //var_dump($this->_role->hasExclusiveAccess($model->getWebsiteIds())); //echo "|"; if (!$this->_role->hasExclusiveAccess($model->getWebsiteIds())) { //echo "here?"; $model->unlockAttributes(); $attributes = $model->getAttributes(); foreach ($attributes as $attribute) { /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ if ($attribute->isScopeGlobal() || $attribute->isScopeWebsite() && count($this->_role->getWebsiteIds()) == 0 || !in_array($model->getStore()->getId(), $this->_role->getStoreIds())) { $model->lockAttribute($attribute->getAttributeCode()); } } $model->setInventoryReadonly(true); $model->setRelatedReadonly(true); $model->setCrosssellReadonly(true); $model->setUpsellReadonly(true); $model->setWebsitesReadonly(true); $model->lockAttribute('website_ids'); $model->setOptionsReadonly(true); $model->setCompositeReadonly(true); if (!in_array($model->getStore()->getId(), $this->_role->getStoreIds())) { $model->setAttributesConfigurationReadonly(true); } $model->setDownloadableReadonly(true); $model->setGiftCardReadonly(true); $model->setIsDeleteable(false); $model->setIsDuplicable(false); $model->unlockAttribute('category_ids'); foreach ($model->getCategoryCollection() as $category) { $path = implode("/", array_reverse($category->getPathIds())); if (!$this->_role->hasExclusiveCategoryAccess($path)) { $model->setCategoriesReadonly(true); $model->lockAttribute('category_ids'); break; } } if (!$this->_role->hasStoreAccess($model->getStoreIds())) { $model->setIsReadonly(true); } } else { /* * We should check here amount of websites to which admin user assigned * and not to those product itself. So if admin user assigned * only to one website we will disable ability to unassign product * from this one website */ if (count($this->_role->getWebsiteIds()) == 1) { $model->setWebsitesReadonly(true); $model->lockAttribute('website_ids'); } } }
/** * Prepare product attribute html output * * @param Mage_Catalog_Model_Product $product * @param string $attributeHtml * @param string $attributeName * @return string */ public function productAttribute($product, $attributeHtml, $attributeName) { $attributes = $product->getAttributes(); $attribute = isset($attributes[$attributeName]) ? $attributes[$attributeName] : null; if ($attribute && $attribute->getFrontendInput() != 'media_image' && (!$attribute->getIsHtmlAllowedOnFront() && !$attribute->getIsWysiwygEnabled())) { $attributeHtml = $this->htmlEscape($attributeHtml); } $attributeHtml = $this->process('productAttribute', $attributeHtml, array('product' => $product, 'attribute' => $attributeName)); return $attributeHtml; }
/** * Amends the product attributes to tags array if attributes are defined * and are present in product * * @param Mage_Catalog_Model_Product $product the product model. * @param Mage_Core_Model_Store $store the store model. * */ protected function amendAttributeTags(Mage_Catalog_Model_Product $product, Mage_Core_Model_Store $store) { $product_attributes = $product->getAttributes(); /* @var Nosto_Tagging_Helper_Data $nosto_helper */ $nosto_helper = Mage::helper("nosto_tagging"); foreach (Nosto_Tagging_Helper_Data::$validTags as $tag_id) { $attributes_to_tag = $nosto_helper->getAttributesToTag($tag_id, $store->getId()); if (empty($attributes_to_tag) || !is_array($attributes_to_tag)) { continue; } /* @var Mage_Catalog_Model_Resource_Eav_Attribute $product_attribute*/ foreach ($product_attributes as $key => $product_attribute) { if (in_array($key, $attributes_to_tag)) { try { $attribute_value = $this->getAttributeValue($product, $key); if (!empty($attribute_value)) { $this->_tags[$tag_id][] = sprintf('%s:%s', $key, $attribute_value); } } catch (Exception $e) { Mage::log(sprintf('Failed to add attribute %s to tags. Error message was: %s', $key, $e->getMessage()), Zend_Log::WARN, Nosto_Tagging_Model_Base::LOG_FILE_NAME); } } } } }
/** * Retrieve the attributes which are visible on the checkout page * * @param Mage_Catalog_Model_Product $product * @return array */ protected function _getAdditionalData(Mage_Catalog_Model_Product $product) { $data = array(); $attributes = $product->getAttributes(); foreach ($attributes as $attribute) { if ($attribute->getIsVisibleOnCheckout()) { $value = $attribute->getFrontend()->getValue($product); if (!$product->hasData($attribute->getAttributeCode()) || (string) $value == '') { $value = ''; } elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) { $value = Mage::app()->getStore()->convertPrice($value, true); } if (is_string($value) && strlen($value)) { $data[$attribute->getAttributeCode()] = array('label' => $attribute->getStoreLabel(), 'value' => $value, 'print_value' => $value, 'code' => $attribute->getAttributeCode()); } } } return $data; }
/** * Set value of not changed attributes to false to prevents from copying * attribute's values to current scope if user selected Current store * option of Save edits to setting in admin interface * * Filter out following attributes: * - Gallery attr (is a complex attr with it's own editor) * - Global (setting value of global attr to false removes it globally) * - Non-visible (non-visible attributes can't be edited directly) * - Without input field (this attributes can'be edited directly) * * Filtering rules are taken from: * - Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes::_prepareForm() * - Mage_Adminhtml_Block_Widget_Form::_setFieldset() * * @param Mage_Catalog_Model_Product $product Product * @param array $changed Key-based list of updated attributes * @param array $globalData Global values */ protected function _unsetValues($product, $changed, $globalData) { foreach ($product->getAttributes() as $code => $attr) { if (isset($changed[$code])) { continue; } // We need to find out if an attribute has a per-store value that // is different than the global value. If so, do Not mark the // field as 'use default'. // Global default is store_id==0 if (isset($globalData[$code])) { if ($globalData[$code] != $product->getData($code)) { continue; } } $allow = $code != 'gallery' && $attr->getIsGlobal() != Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL && $attr->getIsVisible() && $attr->getFrontend()->getInputType(); if (!$allow) { continue; } $product->setData($code, false)->setOrigData($code, false); } }
/** * Returns the attribute code for the "size" attribute for the product. * * @param Mage_Catalog_Model_Product $product * @param bool $one true if we want only one code, false if we want a list. * * @return string The attribute code. */ protected function getSizeAttributeCodes(Mage_Catalog_Model_Product $product, $one = true) { $attributeCodes = array(); $sizeAttributeIds = $this->getSizeAttributeIds(); foreach ($product->getAttributes() as $attribute) { if (in_array($attribute->getAttributeId(), $sizeAttributeIds)) { $attributeCodes[] = $attribute->getAttributeCode(); } } return $one ? array_pop($attributeCodes) : $attributeCodes; }