public function getAttributeValueField($code = '', $i, $j, $current = '') { $html = ''; if ($code) { $attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($code); if ($attribute && ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') || $code == 'product_type') { $options = array(); if ($code == 'product_type') { $attribute_options = Mage_Catalog_Model_Product_Type::getOptions(); } else { $attribute_options = $attribute->getSource()->getAllOptions(); } foreach ($attribute_options as $option) { extract($option); $selected = ''; if ($current == $value) { $selected = 'selected="selected"'; } $options[] = "<option value=\"{$value}\" {$selected}>{$label}</option>"; } $html = '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="option[' . $i . '][condition][' . $j . '][value]">' . implode('', $options) . '</select>'; } } if ($html) { return $html; } else { return '<input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="option[' . $i . '][condition][' . $j . '][value]" value="' . $current . '"/>'; } }
/** * Retrieve product type list * * @return array */ public function items() { $result = array(); foreach (Mage_Catalog_Model_Product_Type::getOptionArray() as $type => $label) { $result[] = array('type' => $type, 'label' => $label); } return $result; }
/** * Internal Constructor */ protected function _construct() { parent::_construct(); $this->_init('widget/widget_instance'); $this->_layoutHandles = array('anchor_categories' => self::ANCHOR_CATEGORY_LAYOUT_HANDLE, 'notanchor_categories' => self::NOTANCHOR_CATEGORY_LAYOUT_HANDLE, 'all_products' => self::PRODUCT_LAYOUT_HANDLE, 'all_pages' => self::DEFAULT_LAYOUT_HANDLE); $this->_specificEntitiesLayoutHandles = array('anchor_categories' => self::SINGLE_CATEGORY_LAYOUT_HANDLE, 'notanchor_categories' => self::SINGLE_CATEGORY_LAYOUT_HANDLE, 'all_products' => self::SINGLE_PRODUCT_LAYOUT_HANLDE); foreach (Mage_Catalog_Model_Product_Type::getTypes() as $typeId => $type) { $this->_layoutHandles[$typeId . '_products'] = str_replace('{{TYPE}}', $typeId, self::PRODUCT_TYPE_LAYOUT_HANDLE); $this->_specificEntitiesLayoutHandles[$typeId . '_products'] = self::SINGLE_PRODUCT_LAYOUT_HANLDE; } }
protected function _prepareForm() { /* @var $form Varien_Data_Form */ $form = new Varien_Data_Form(); /* @var $fieldset Varien_Data_Form_Element_Fieldset */ $fieldset = $form->addFieldset('permissions_product_create', array('legend' => Mage::helper('aitpermissions')->__('Product Creation Permissions'))); $this->_addElementTypes($fieldset); $fieldset->addField('allow_create_product', 'select', array('name' => 'allow_create_product', 'label' => Mage::helper('aitpermissions')->__('Allow to Сreate Products'), 'title' => Mage::helper('aitpermissions')->__('Allow to Сreate Products'), 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray())); $fieldset->addField('apply_to', 'apply', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Allow to Create'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types'))), 'frontend_class'); $this->setForm($form); $this->_setFormValues($form); }
/** * Retrieve Product Type Instances * as key - type code, value - instance model * * @return array */ public function getProductTypeInstances() { if (is_null($this->_productTypes)) { $this->_productTypes = array(); $productEmulator = new Varien_Object(); foreach (array_keys(Mage_Catalog_Model_Product_Type::getTypes()) as $typeId) { $productEmulator->setTypeId($typeId); $this->_productTypes[$typeId] = Mage::getSingleton('catalog/product_type')->factory($productEmulator); } } return $this->_productTypes; }
protected function _prepareForm() { $model = Mage::registry('entity_attribute'); $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('catalog')->__('Attribute Properties'))); if ($model->getAttributeId()) { $fieldset->addField('attribute_id', 'hidden', array('name' => 'attribute_id')); } $yesno = array(array('value' => 0, 'label' => Mage::helper('catalog')->__('No')), array('value' => 1, 'label' => Mage::helper('catalog')->__('Yes'))); $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => Mage::helper('catalog')->__('Attribute Identifier'), 'title' => Mage::helper('catalog')->__('Attribute Identifier'), 'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'), 'class' => 'validate-code', 'required' => true)); $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => Mage::helper('catalog')->__('Scope'), 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare atrribute value saving scope'), 'values' => array(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => Mage::helper('catalog')->__('Website'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global')))); $fieldset->addField('frontend_input', 'select', array('name' => 'frontend_input', 'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => array(array('value' => 'text', 'label' => Mage::helper('catalog')->__('Text Field')), array('value' => 'textarea', 'label' => Mage::helper('catalog')->__('Text Area')), array('value' => 'date', 'label' => Mage::helper('catalog')->__('Date')), array('value' => 'boolean', 'label' => Mage::helper('catalog')->__('Yes/No')), array('value' => 'multiselect', 'label' => Mage::helper('catalog')->__('Multiple Select')), array('value' => 'select', 'label' => Mage::helper('catalog')->__('Dropdown')), array('value' => 'price', 'label' => Mage::helper('catalog')->__('Price')), array('value' => 'image', 'label' => Mage::helper('catalog')->__('Image')), array('value' => 'gallery', 'label' => Mage::helper('catalog')->__('Gallery')), array('value' => 'media_image', 'label' => Mage::helper('catalog')->__('Media Image'))))); $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'values' => $yesno, 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('is_unique', 'select', array('name' => 'is_unique', 'label' => Mage::helper('catalog')->__('Unique Value'), 'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'), 'note' => Mage::helper('catalog')->__('Not shared with other products'), 'values' => $yesno)); $fieldset->addField('is_required', 'select', array('name' => 'is_required', 'label' => Mage::helper('catalog')->__('Values Required'), 'title' => Mage::helper('catalog')->__('Values Required'), 'values' => $yesno)); $fieldset->addField('frontend_class', 'select', array('name' => 'frontend_class', 'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'values' => array(array('value' => '', 'label' => Mage::helper('catalog')->__('None')), array('value' => 'validate-number', 'label' => Mage::helper('catalog')->__('Decimal Number')), array('value' => 'validate-digits', 'label' => Mage::helper('catalog')->__('Integer Number')), array('value' => 'validate-email', 'label' => Mage::helper('catalog')->__('Email')), array('value' => 'validate-url', 'label' => Mage::helper('catalog')->__('Url')), array('value' => 'validate-alpha', 'label' => Mage::helper('catalog')->__('Letters')), array('value' => 'validate-alphanum', 'label' => Mage::helper('catalog')->__('Letters(a-z) or Numbers(0-9)'))))); /* $fieldset->addField('use_in_super_product', 'select', array( 'name' => 'use_in_super_product', 'label' => Mage::helper('catalog')->__('Apply To Configurable/Grouped Product'), 'values' => $yesno, )); */ $fieldset->addField('apply_to', 'multiselect', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'value' => array(Mage_Catalog_Model_Product_Type::DEFAULT_TYPE), 'required' => true)); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), 'values' => $yesno)); // ----- // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend' => Mage::helper('catalog')->__('Frontend Properties'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in quick search'), 'title' => Mage::helper('catalog')->__('Use in quick search'), 'values' => $yesno)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in advanced search'), 'title' => Mage::helper('catalog')->__('Use in advanced search'), 'values' => $yesno)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), 'values' => $yesno)); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown'), 'values' => array(array('value' => '0', 'label' => Mage::helper('catalog')->__('No')), array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')), array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)'))))); if ($model->getIsUserDefined() || !$model->getId()) { $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Catalog Pages on Front-end'), 'values' => $yesno)); } if ($model->getId()) { $form->getElement('attribute_code')->setDisabled(1); $form->getElement('frontend_input')->setDisabled(1); } if (!$model->getIsUserDefined() && $model->getId()) { $form->getElement('is_unique')->setDisabled(1); } $form->addValues($model->getData()); if ($model->getApplyTo()) { $form->getElement('apply_to')->setValue(explode(',', $model->getApplyTo())); } $this->setForm($form); return parent::_prepareForm(); }
public function convertAction() { if ($this->getRequest()->getParam('id') > 0) { try { $product = Mage::getModel('catalog/product')->load($this->getRequest()->getParam('id')); $old_type = $product->getTypeId(); $new_type = 'subscription_' . $old_type; $types = Mage_Catalog_Model_Product_Type::getTypes(); if (empty($types[$new_type]['model'])) { throw new Mage_Core_Exception("The product type {$old_type} can't be converted"); } $this->__beforeConvert($product, $new_type); $product->setTypeId($new_type)->save(); Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('sarp')->__('Product was successfully converted to subscription')); $this->_redirect('*/*/'); } catch (Exception $e) { Mage::getSingleton('adminhtml/session')->addError($e->getMessage()); } } $this->_redirectReferer(); }
/** * Creates the form for the condition based selection of product attributes. * * @return FireGento_DynamicCategory_Block_Adminhtml_Category_Dynamic Self. */ public function _prepareLayout() { parent::_prepareLayout(); $model = Mage::getSingleton('mep/rule'); $data = array(); if ($this->getCategory() != null) { $conditions = $this->getCategory()->getConditionsSerialized(); if (!is_array($conditions)) { $conditions = unserialize($conditions); } $data['conditions'] = $conditions; } $model->loadPost($data); $form = new Varien_Data_Form(); $form->setHtmlIdPrefix('mep_'); $form->setDataObject($this->getCategory()); $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')->setTemplate('mep/fieldset.phtml')->setNewChildUrl($this->getUrl('adminhtml/dynamic/newConditionHtml/form/mep_conditions_fieldset')); $fieldset = $form->addFieldset('conditions_fieldset', array('legend' => $this->__('Export Rules')))->setRenderer($renderer); $fieldset->addField('conditions', 'text', array('name' => 'conditions', 'label' => $this->__('Conditions'), 'title' => $this->__('Conditions')))->setRule($model)->setRenderer(Mage::getBlockSingleton('mep/conditions')); $specialRules = $form->addFieldset('special_rules_fieldset', array('legend' => $this->__('Special filters'))); $specialRules->addType('apply', 'Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Apply'); $specialRules->addField('apply_to', 'apply', array('name' => 'settings[apply_to][]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types')), 'required' => true), 'frontend_class'); $form->getElement('apply_to')->setValue($this->getApplyToValue($form)); $specialRules->addField('is_in_stock', 'select', array('name' => 'settings[is_in_stock]', 'label' => Mage::helper('catalog')->__('Stock Availability'), 'values' => array_merge(Mage::getSingleton('cataloginventory/source_stock')->toOptionArray(), array('2' => '')), 'value' => $this->getProfilSettingsValueForKey('is_in_stock'), 'note' => $this->__('Will be used for mains and inheritors products'))); $specialRules->addType('qty', 'Flagbit_MEP_Helper_QtyFilter'); $specialRules->addField('qty', 'qty', array('name' => 'settings[qty][threshold]', 'dropdownName' => 'settings[qty][operator]', 'dropdownStyle' => 'width: 150px', 'dropdownValue' => $this->getQtyOperatorValue(), 'label' => Mage::helper('catalog')->__('Qty'), 'style' => 'width:50px', 'note' => $this->__('Will be used for mains and inheritors products'), 'required' => true)); $form->getElement('qty')->setValue($this->getQtyFilterValue($form)); $profilData = Mage::helper('mep')->getCurrentProfileData(); $settings = $profilData['settings']; if (!$settings) { $form->getElement('apply_to')->addClass('no-display ignore-validate'); $form->getElement('qty')->addClass('no-display ignore-validate'); } $this->setForm($form); return $this; }
/** * Automaticaly assign backend model to weee attributes * * @param Varien_Event_Observer $observer * @return Mage_Weee_Model_Observer */ public function assignBackendModelToAttribute(Varien_Event_Observer $observer) { $backendModel = Mage_Weee_Model_Attribute_Backend_Weee_Tax::getBackendModelName(); /** @var $object Mage_Eav_Model_Entity_Attribute_Abstract */ $object = $observer->getEvent()->getAttribute(); if ($object->getFrontendInput() == 'weee') { $object->setBackendModel($backendModel); if (!$object->getApplyTo()) { $applyTo = array(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $option) { if ($option['value'] == Mage_Catalog_Model_Product_Type::TYPE_GROUPED) { continue; } $applyTo[] = $option['value']; } $object->setApplyTo($applyTo); } } return $this; }
/** * Generate array of parameters for every container type to create html template * * @return array */ public function getDisplayOnContainers() { $container = array(); $container['anchor'] = array('label' => 'Categories', 'code' => 'categories', 'name' => 'anchor_categories', 'layout_handle' => 'default,catalog_category_layered', 'is_anchor_only' => 1, 'product_type_id' => ''); $container['notanchor'] = array('label' => 'Categories', 'code' => 'categories', 'name' => 'notanchor_categories', 'layout_handle' => 'default,catalog_category_default', 'is_anchor_only' => 0, 'product_type_id' => ''); $container['all_products'] = array('label' => 'Products', 'code' => 'products', 'name' => 'all_products', 'layout_handle' => 'default,catalog_product_view', 'is_anchor_only' => '', 'product_type_id' => ''); foreach (Mage_Catalog_Model_Product_Type::getTypes() as $typeId => $type) { $container[$typeId] = array('label' => 'Products', 'code' => 'products', 'name' => $typeId . '_products', 'layout_handle' => 'default,catalog_product_view,PRODUCT_TYPE_' . $typeId, 'is_anchor_only' => '', 'product_type_id' => $typeId); } return $container; }
/** * @return Mage_Catalog_Model_Product_Type_Abstract * @throws Ess_M2ePro_Model_Exception */ public function getTypeInstance() { if (is_null($this->_productModel) && $this->_productId < 0) { throw new Ess_M2ePro_Model_Exception('Load instance first'); } /** @var Mage_Catalog_Model_Product_Type_Abstract $typeInstance */ if ($this->isConfigurableType() && !$this->getProduct()->getData('overridden_type_instance_injected')) { $config = Mage_Catalog_Model_Product_Type::getTypes(); $typeInstance = Mage::getModel('M2ePro/Magento_Product_Type_Configurable'); $typeInstance->setProduct($this->getProduct()); $typeInstance->setConfig($config['configurable']); $this->getProduct()->setTypeInstance($typeInstance); $this->getProduct()->setTypeInstance($typeInstance, true); $this->getProduct()->setData('overridden_type_instance_injected', true); } else { $typeInstance = $this->getProduct()->getTypeInstance(); } $typeInstance->setStoreFilter($this->getStoreId()); return $typeInstance; }
public function getProductsCollection($filterData = '', $current_page = 0, $length = 50) { if (is_null($this->_productCollection) && $this->getId()) { $collection = Mage::getModel('gomage_feed/product_collection')->addAttributeToSelect('*'); $collection->addStoreFilter(Mage::app()->getStore()); if ($length != 0) { $collection->setPage($current_page + 1, $length); } $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addUrlRewrite($this->getRootCategory()->getId()); if ($this->getVisibility()) { switch ($this->getVisibility()) { case Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE: $collection->setVisibility(array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE)); break; case Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG: Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection); break; case Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH: Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection); break; case Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH: Mage::getSingleton('catalog/product_visibility')->addVisibleInSiteFilterToCollection($collection); break; case 5: $collection->setVisibility(array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG)); break; case 6: $collection->setVisibility(array(Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH)); break; } } if ($this->getUseLayer()) { $collection->joinField('is_in_stock', 'cataloginventory/stock_item', 'is_in_stock', 'product_id=entity_id'); $collection->addAttributeToFilter('is_in_stock', array('eq' => Mage_CatalogInventory_Model_Stock::STOCK_IN_STOCK)); } if ($this->getUseDisabled()) { Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection); $collection->addAttributeToFilter('status', array('in' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)); } if ($this->getFilter()) { $filter_values = json_decode($this->getFilter(), true); $filters = array(); foreach ((array) $filter_values as $filter) { $code = trim(@$filter['attribute_code']); $condition = trim(@$filter['condition']); $value = trim(@$filter['value']); if ($code && $condition && $value != '') { if (!isset($filters[$code])) { $filters[$code] = array(); } if (!isset($filters[$code][$condition])) { $filters[$code][$condition] = array(); } $filters[$code][$condition][] = $value; } } foreach ($filters as $code => $filter) { if ($code == 'qty') { $collection->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left'); } foreach ($filter as $condition => $value) { if ($code == 'category_id') { foreach ($value as $_value) { $collection->prepareFeedCategoryFilter($condition, $_value); } } elseif ($code == 'product_type') { $all_product_type = Mage_Catalog_Model_Product_Type::getOptionArray(); $all_product_type = array_keys($all_product_type); if (isset($filter['neq'])) { $all_product_type = array_diff($all_product_type, $filter['neq']); } if (isset($filter['eq'])) { $all_product_type = array_intersect($all_product_type, $filter['eq']); } $collection->addAttributeToFilter('type_id', array('in' => $all_product_type)); break; } else { switch ($condition) { case 'eq': $condition = 'in'; break; case 'neq': $condition = 'nin'; break; case 'gt': case 'gteq': $value = max($value); break; case 'lt': case 'lteq': $value = min($value); break; case 'like': if (count($value) > 1) { $_attribute = array(); foreach ($value as $_value) { $_attribute[] = array('attribute' => $code, $condition => $_value); } $collection->addAttributeToFilter($_attribute); continue 2; } else { $value = $value[0]; } case 'nlike': foreach ($value as $_value) { $collection->addAttributeToFilter($code, array($condition => $_value)); } continue 2; break; } $collection->addAttributeToFilter($code, array($condition => $value)); } } } if (isset($filters['category_id'])) { $collection->addFeedCategoryFilter(); } } $this->_productCollection = $collection; } return $this->_productCollection; }
public function getAllOptions() { if (!$this->_ready) { return array(array('value' => '', 'label' => Mage::helper('widget')->__('-- Please Select --'))); } $result = array(array('value' => '', 'label' => Mage::helper('widget')->__('-- Please Select --')), array('label' => Mage::helper('widget')->__('Categories'), 'value' => array(array('value' => 'catalog_category_layered', 'label' => Mage::helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Anchor Categories'))), array('value' => 'catalog_category_default', 'label' => Mage::helper('core')->jsQuoteEscape(Mage::helper('widget')->__('Non-Anchor Categories')))))); $productTypes = array(); foreach (Mage_Catalog_Model_Product_Type::getTypes() as $typeId => $type) { $productTypes[] = array('value' => 'PRODUCT_TYPE_' . $typeId, 'label' => Mage::helper('core')->jsQuoteEscape($type['label'])); } array_unshift($productTypes, array('value' => 'catalog_product_view', 'label' => Mage::helper('core')->jsQuoteEscape(Mage::helper('widget')->__('All Product Types')))); $result[] = array('label' => Mage::helper('widget')->__('Products'), 'value' => $productTypes); $pages = array(array('value' => 'default', 'label' => Mage::helper('widget')->__('All Pages'))); foreach ($this->getLayoutHandles($this->getArea(), $this->getPackage(), $this->getTheme()) as $value => $label) { $pages[] = array('value' => $value, 'label' => $label); } $result[] = array('label' => Mage::helper('widget')->__('Generic Pages'), 'value' => $pages); return $result; }
public function getProductType($val) { if (is_null($this->_productTypes)) { $this->_productTypes = array(); $retarray = Mage_Catalog_Model_Product_Type::getOptions(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $value) { $this->_productTypes['value'][] = $value['value']; $this->_productTypes['label'][] = $value['label']; } } $val = str_replace($this->_productTypes['value'], $this->_productTypes['label'], $val); return $val; }
/** * Adding product form elements for editing attribute * * @return Mage_Adminhtml_Block_Catalog_Product_Attribute_Edit_Tab_Main */ protected function _prepareForm() { parent::_prepareForm(); $attributeObject = $this->getAttributeObject(); /* @var $form Varien_Data_Form */ $form = $this->getForm(); /* @var $fieldset Varien_Data_Form_Element_Fieldset */ $fieldset = $form->getElement('base_fieldset'); $frontendInputElm = $form->getElement('frontend_input'); $additionalTypes = array(array('value' => 'price', 'label' => Mage::helper('catalog')->__('Price')), array('value' => 'media_image', 'label' => Mage::helper('catalog')->__('Media Image'))); if ($attributeObject->getFrontendInput() == 'gallery') { $additionalTypes[] = array('value' => 'gallery', 'label' => Mage::helper('catalog')->__('Gallery')); } $response = new Varien_Object(); $response->setTypes(array()); Mage::dispatchEvent('adminhtml_product_attribute_types', array('response' => $response)); $_disabledTypes = array(); $_hiddenFields = array(); foreach ($response->getTypes() as $type) { $additionalTypes[] = $type; if (isset($type['hide_fields'])) { $_hiddenFields[$type['value']] = $type['hide_fields']; } if (isset($type['disabled_types'])) { $_disabledTypes[$type['value']] = $type['disabled_types']; } } Mage::register('attribute_type_hidden_fields', $_hiddenFields); Mage::register('attribute_type_disabled_types', $_disabledTypes); $frontendInputValues = array_merge($frontendInputElm->getValues(), $additionalTypes); $frontendInputElm->setValues($frontendInputValues); $yesnoSource = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(); $scopes = array(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => Mage::helper('catalog')->__('Website'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global')); if ($attributeObject->getAttributeCode() == 'status' || $attributeObject->getAttributeCode() == 'tax_class_id') { unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]); } $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => Mage::helper('catalog')->__('Scope'), 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'), 'values' => $scopes), 'attribute_code'); $fieldset->addField('apply_to', 'apply', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types')), 'required' => true), 'frontend_class'); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), 'values' => $yesnoSource), 'apply_to'); // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend' => Mage::helper('catalog')->__('Frontend Properties'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in Quick Search'), 'title' => Mage::helper('catalog')->__('Use in Quick Search'), 'values' => $yesnoSource)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in Advanced Search'), 'title' => Mage::helper('catalog')->__('Use in Advanced Search'), 'values' => $yesnoSource)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), 'values' => $yesnoSource)); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => array(array('value' => '0', 'label' => Mage::helper('catalog')->__('No')), array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')), array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)'))))); $fieldset->addField('is_filterable_in_search', 'select', array('name' => 'is_filterable_in_search', 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => $yesnoSource)); $fieldset->addField('is_used_for_promo_rules', 'select', array('name' => 'is_used_for_promo_rules', 'label' => Mage::helper('catalog')->__('Use for Promo Rule Conditions'), 'title' => Mage::helper('catalog')->__('Use for Promo Rule Conditions'), 'values' => $yesnoSource)); $fieldset->addField('position', 'text', array('name' => 'position', 'label' => Mage::helper('catalog')->__('Position'), 'title' => Mage::helper('catalog')->__('Position in Layered Navigation'), 'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'), 'class' => 'validate-digits')); $fieldset->addField('is_wysiwyg_enabled', 'select', array('name' => 'is_wysiwyg_enabled', 'label' => Mage::helper('catalog')->__('Enable WYSIWYG'), 'title' => Mage::helper('catalog')->__('Enable WYSIWYG'), 'values' => $yesnoSource)); $htmlAllowed = $fieldset->addField('is_html_allowed_on_front', 'select', array('name' => 'is_html_allowed_on_front', 'label' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'), 'title' => Mage::helper('catalog')->__('Allow HTML Tags on Frontend'), 'values' => $yesnoSource)); if (!$attributeObject->getId() || $attributeObject->getIsWysiwygEnabled()) { $attributeObject->setIsHtmlAllowedOnFront(1); } $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'values' => $yesnoSource)); $fieldset->addField('used_in_product_listing', 'select', array('name' => 'used_in_product_listing', 'label' => Mage::helper('catalog')->__('Used in Product Listing'), 'title' => Mage::helper('catalog')->__('Used in Product Listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesnoSource)); $fieldset->addField('used_for_sort_by', 'select', array('name' => 'used_for_sort_by', 'label' => Mage::helper('catalog')->__('Used for Sorting in Product Listing'), 'title' => Mage::helper('catalog')->__('Used for Sorting in Product Listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesnoSource)); $form->getElement('apply_to')->setSize(5); if ($applyTo = $attributeObject->getApplyTo()) { $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo); $form->getElement('apply_to')->setValue($applyTo); } else { $form->getElement('apply_to')->addClass('no-display ignore-validate'); } // define field dependencies $this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')->addFieldMap("is_wysiwyg_enabled", 'wysiwyg_enabled')->addFieldMap("is_html_allowed_on_front", 'html_allowed_on_front')->addFieldMap("frontend_input", 'frontend_input_type')->addFieldDependence('wysiwyg_enabled', 'frontend_input_type', 'textarea')->addFieldDependence('html_allowed_on_front', 'wysiwyg_enabled', '0')); Mage::dispatchEvent('adminhtml_catalog_product_attribute_edit_prepare_form', array('form' => $form, 'attribute' => $attributeObject)); return $this; }
/* @var $this Mage_Core_Model_Resource_Setup */ /** @var $indexHelper Enterprise_Index_Helper_Data */ $indexHelper = Mage::helper('enterprise_index'); /** @var $client Enterprise_Mview_Model_Client */ $client = Mage::getModel('enterprise_mview/client'); $client->init('catalogsearch_fulltext'); $client->getMetadata()->setKeyColumn('product_id')->setViewName('catalogsearch_fulltext_cl')->setStatus(Enterprise_Mview_Model_Metadata::STATUS_INVALID)->setGroupCode('catalogsearch_fulltext')->save(); $client->execute('enterprise_index/action_index_changelog_create'); $subscriptions = array($this->getTable('catalog/product') => 'entity_id', $this->getTable(array('catalog/product', 'decimal')) => 'entity_id', $this->getTable(array('catalog/product', 'int')) => 'entity_id', $this->getTable(array('catalog/product', 'text')) => 'entity_id', $this->getTable(array('catalog/product', 'varchar')) => 'entity_id', $this->getTable(array('catalog/product', 'datetime')) => 'entity_id'); /** @var $resources mage_core_model_resource */ $resources = Mage::getSingleton('core/resource'); /** @var $productType mage_catalog_model_product_type */ $productType = Mage::getSingleton('catalog/product_type'); $productEmulator = new Varien_Object(); $productEmulator->setIdFieldName('entity_id'); foreach (Mage_Catalog_Model_Product_Type::getCompositeTypes() as $typeId) { $productEmulator->setTypeId($typeId); /** @var $typeInstance Mage_Catalog_Model_Product_Type_Abstract */ $typeInstance = $productType->factory($productEmulator); /** @var $relation bool|Varien_Object */ $relation = $typeInstance->isComposite() ? $typeInstance->getRelationInfo() : false; if ($relation && $relation->getTable()) { $tableName = $resources->getTableName($relation->getTable()); $subscriptions[$tableName] = $relation->getParentFieldName(); } } foreach ($subscriptions as $targetTable => $targetColumn) { $arguments = array('target_table' => $targetTable, 'target_column' => $targetColumn); $client->execute('enterprise_mview/action_changelog_subscription_create', $arguments); } $events = array();
public function testGetTypesByPriority() { $types = Mage_Catalog_Model_Product_Type::getTypesByPriority(); // collect the types and priority in the same order as the method returns $result = array(); foreach ($types as $typeId => $type) { if (!isset($type['index_priority'])) { // possible bug: index_priority is not defined for each type $priority = 0; } else { $priority = (int) $type['index_priority']; } // non-composite must be before composite if (1 != $type['composite']) { $priority = -1 * $priority; } $result[$typeId] = $priority; } $expectedResult = $result; asort($expectedResult); $this->assertEquals($expectedResult, $result); }
public function toOptionArray() { return Mage_Catalog_Model_Product_Type::getOptions(); }
protected function _prepareForm() { $model = Mage::registry('entity_attribute'); $form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getData('action'), 'method' => 'post')); $disableAttributeFields = array('sku' => array('is_global', 'is_unique'), 'url_key' => array('is_unique')); $fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('catalog')->__('Attribute Properties'))); if ($model->getAttributeId()) { $fieldset->addField('attribute_id', 'hidden', array('name' => 'attribute_id')); } $this->_addElementTypes($fieldset); $yesno = array(array('value' => 0, 'label' => Mage::helper('catalog')->__('No')), array('value' => 1, 'label' => Mage::helper('catalog')->__('Yes'))); $fieldset->addField('attribute_code', 'text', array('name' => 'attribute_code', 'label' => Mage::helper('catalog')->__('Attribute Code'), 'title' => Mage::helper('catalog')->__('Attribute Code'), 'note' => Mage::helper('catalog')->__('For internal use. Must be unique with no spaces'), 'class' => 'validate-code', 'required' => true)); $scopes = array(Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE => Mage::helper('catalog')->__('Store View'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_WEBSITE => Mage::helper('catalog')->__('Website'), Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL => Mage::helper('catalog')->__('Global')); if ($model->getAttributeCode() == 'status' || $model->getAttributeCode() == 'tax_class_id') { unset($scopes[Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE]); } $fieldset->addField('is_global', 'select', array('name' => 'is_global', 'label' => Mage::helper('catalog')->__('Scope'), 'title' => Mage::helper('catalog')->__('Scope'), 'note' => Mage::helper('catalog')->__('Declare attribute value saving scope'), 'values' => $scopes)); $inputTypes = array(array('value' => 'text', 'label' => Mage::helper('catalog')->__('Text Field')), array('value' => 'textarea', 'label' => Mage::helper('catalog')->__('Text Area')), array('value' => 'date', 'label' => Mage::helper('catalog')->__('Date')), array('value' => 'boolean', 'label' => Mage::helper('catalog')->__('Yes/No')), array('value' => 'multiselect', 'label' => Mage::helper('catalog')->__('Multiple Select')), array('value' => 'select', 'label' => Mage::helper('catalog')->__('Dropdown')), array('value' => 'price', 'label' => Mage::helper('catalog')->__('Price')), array('value' => 'gallery', 'label' => Mage::helper('catalog')->__('Gallery')), array('value' => 'media_image', 'label' => Mage::helper('catalog')->__('Media Image'))); $response = new Varien_Object(); $response->setTypes(array()); Mage::dispatchEvent('adminhtml_product_attribute_types', array('response' => $response)); $_disabledTypes = array(); $_hiddenFields = array(); foreach ($response->getTypes() as $type) { $inputTypes[] = $type; if (isset($type['hide_fields'])) { $_hiddenFields[$type['value']] = $type['hide_fields']; } if (isset($type['disabled_types'])) { $_disabledTypes[$type['value']] = $type['disabled_types']; } } Mage::register('attribute_type_hidden_fields', $_hiddenFields); Mage::register('attribute_type_disabled_types', $_disabledTypes); $fieldset->addField('frontend_input', 'select', array('name' => 'frontend_input', 'label' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'title' => Mage::helper('catalog')->__('Catalog Input Type for Store Owner'), 'value' => 'text', 'values' => $inputTypes)); $fieldset->addField('default_value_text', 'text', array('name' => 'default_value_text', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('default_value_yesno', 'select', array('name' => 'default_value_yesno', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'values' => $yesno, 'value' => $model->getDefaultValue())); $dateFormatIso = Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT); $fieldset->addField('default_value_date', 'date', array('name' => 'default_value_date', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'image' => $this->getSkinUrl('images/grid-cal.gif'), 'value' => $model->getDefaultValue(), 'format' => $dateFormatIso)); $fieldset->addField('default_value_textarea', 'textarea', array('name' => 'default_value_textarea', 'label' => Mage::helper('catalog')->__('Default value'), 'title' => Mage::helper('catalog')->__('Default value'), 'value' => $model->getDefaultValue())); $fieldset->addField('is_unique', 'select', array('name' => 'is_unique', 'label' => Mage::helper('catalog')->__('Unique Value'), 'title' => Mage::helper('catalog')->__('Unique Value (not shared with other products)'), 'note' => Mage::helper('catalog')->__('Not shared with other products'), 'values' => $yesno)); $fieldset->addField('is_required', 'select', array('name' => 'is_required', 'label' => Mage::helper('catalog')->__('Values Required'), 'title' => Mage::helper('catalog')->__('Values Required'), 'values' => $yesno)); $fieldset->addField('frontend_class', 'select', array('name' => 'frontend_class', 'label' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'title' => Mage::helper('catalog')->__('Input Validation for Store Owner'), 'values' => array(array('value' => '', 'label' => Mage::helper('catalog')->__('None')), array('value' => 'validate-number', 'label' => Mage::helper('catalog')->__('Decimal Number')), array('value' => 'validate-digits', 'label' => Mage::helper('catalog')->__('Integer Number')), array('value' => 'validate-email', 'label' => Mage::helper('catalog')->__('Email')), array('value' => 'validate-url', 'label' => Mage::helper('catalog')->__('Url')), array('value' => 'validate-alpha', 'label' => Mage::helper('catalog')->__('Letters')), array('value' => 'validate-alphanum', 'label' => Mage::helper('catalog')->__('Letters(a-zA-Z) or Numbers(0-9)'))))); /* $fieldset->addField('use_in_super_product', 'select', array( 'name' => 'use_in_super_product', 'label' => Mage::helper('catalog')->__('Apply To Configurable/Grouped Product'), 'values' => $yesno, )); */ $fieldset->addField('apply_to', 'apply', array('name' => 'apply_to[]', 'label' => Mage::helper('catalog')->__('Apply To'), 'values' => Mage_Catalog_Model_Product_Type::getOptions(), 'mode_labels' => array('all' => Mage::helper('catalog')->__('All Product Types'), 'custom' => Mage::helper('catalog')->__('Selected Product Types')), 'required' => true)); $fieldset->addField('is_configurable', 'select', array('name' => 'is_configurable', 'label' => Mage::helper('catalog')->__('Use To Create Configurable Product'), 'values' => $yesno)); // ----- // frontend properties fieldset $fieldset = $form->addFieldset('front_fieldset', array('legend' => Mage::helper('catalog')->__('Frontend Properties'))); $fieldset->addField('is_searchable', 'select', array('name' => 'is_searchable', 'label' => Mage::helper('catalog')->__('Use in quick search'), 'title' => Mage::helper('catalog')->__('Use in quick search'), 'values' => $yesno)); $fieldset->addField('is_visible_in_advanced_search', 'select', array('name' => 'is_visible_in_advanced_search', 'label' => Mage::helper('catalog')->__('Use in advanced search'), 'title' => Mage::helper('catalog')->__('Use in advanced search'), 'values' => $yesno)); $fieldset->addField('is_comparable', 'select', array('name' => 'is_comparable', 'label' => Mage::helper('catalog')->__('Comparable on Front-end'), 'title' => Mage::helper('catalog')->__('Comparable on Front-end'), 'values' => $yesno)); $fieldset->addField('is_filterable', 'select', array('name' => 'is_filterable', 'label' => Mage::helper('catalog')->__("Use In Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => array(array('value' => '0', 'label' => Mage::helper('catalog')->__('No')), array('value' => '1', 'label' => Mage::helper('catalog')->__('Filterable (with results)')), array('value' => '2', 'label' => Mage::helper('catalog')->__('Filterable (no results)'))))); $fieldset->addField('is_filterable_in_search', 'select', array('name' => 'is_filterable_in_search', 'label' => Mage::helper('catalog')->__("Use In Search Results Layered Navigation"), 'title' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'note' => Mage::helper('catalog')->__('Can be used only with catalog input type Dropdown, Multiple Select and Price'), 'values' => $yesno)); $fieldset->addField('is_used_for_price_rules', 'select', array('name' => 'is_used_for_price_rules', 'label' => Mage::helper('catalog')->__('Use for Price Rule Conditions'), 'title' => Mage::helper('catalog')->__('Use for Price Rule Conditions'), 'values' => $yesno)); $fieldset->addField('position', 'text', array('name' => 'position', 'label' => Mage::helper('catalog')->__('Position'), 'title' => Mage::helper('catalog')->__('Position In Layered Navigation'), 'note' => Mage::helper('catalog')->__('Position of attribute in layered navigation block'), 'class' => 'validate-digits')); $htmlAllowed = $fieldset->addField('is_html_allowed_on_front', 'select', array('name' => 'is_html_allowed_on_front', 'label' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'), 'title' => Mage::helper('catalog')->__('Allow HTML-tags on Front-end'), 'values' => $yesno)); if (!$model->getId()) { $htmlAllowed->setValue(1); } $fieldset->addField('is_visible_on_front', 'select', array('name' => 'is_visible_on_front', 'label' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'title' => Mage::helper('catalog')->__('Visible on Product View Page on Front-end'), 'values' => $yesno)); $fieldset->addField('used_in_product_listing', 'select', array('name' => 'used_in_product_listing', 'label' => Mage::helper('catalog')->__('Used in product listing'), 'title' => Mage::helper('catalog')->__('Used in product listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesno)); $fieldset->addField('used_for_sort_by', 'select', array('name' => 'used_for_sort_by', 'label' => Mage::helper('catalog')->__('Used for sorting in product listing'), 'title' => Mage::helper('catalog')->__('Used for sorting in product listing'), 'note' => Mage::helper('catalog')->__('Depends on design theme'), 'values' => $yesno)); if ($model->getId()) { $form->getElement('attribute_code')->setDisabled(1); $form->getElement('frontend_input')->setDisabled(1); if (isset($disableAttributeFields[$model->getAttributeCode()])) { foreach ($disableAttributeFields[$model->getAttributeCode()] as $field) { $form->getElement($field)->setDisabled(1); } } } if (!$model->getIsUserDefined() && $model->getId()) { $form->getElement('is_unique')->setDisabled(1); } $form->addValues($model->getData()); $form->getElement('apply_to')->setSize(5); if ($applyTo = $model->getApplyTo()) { $applyTo = is_array($applyTo) ? $applyTo : explode(',', $applyTo); $form->getElement('apply_to')->setValue($applyTo); } else { $form->getElement('apply_to')->addClass('no-display ignore-validate'); } $this->setForm($form); return parent::_prepareForm(); }
/** * given a DOMNodeList and a Mage_Catalog_Model_Product make sure this is * a product of type configurable and then extract the configurable attribute from the node list * then get the configurable attribute array for each configured attributes * @param DOMNOdeList $nodes the node with configurableAttributes data * @param Mage_Catalog_Model_Product $product * @return array | null an array of configurable attribute data if the given product is configurable otherwise null */ public function extractConfigurableAttributesData(DOMNodeList $nodes, Mage_Catalog_Model_Product $product) { // We are ensuring that the given product is a parent configurable product by first checking if the product sku // doesn't match the product style id. If this condition is met then we know we have a child product and we won't // proceed otherwise we know we have a parent product and proceed continue. if ($product->getSku() !== $this->_normalizeStyleId($product->getStyleId())) { return null; } $typeInstance = $product->getTypeInstance(true); // making sure the right type instance is set on the product if (!$typeInstance instanceof Mage_Catalog_Model_Product_Type_Configurable) { $product->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true); } $data = null; // purposely setting this to null just in cause all the attribute already exists // we need to know which configurable attribute we already have for this product // so that we don't try to create the same super attribute relationship which will // cause unique key duplication SQL constraint to be thrown $existedData = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product); foreach (explode(',', strtolower(Mage::helper('eb2ccore')->extractNodeVal($nodes))) as $attributeCode) { // if we don't currently have a super attribute relationship then get the // configurable attribute data if (!$this->_isSuperAttributeExists($existedData, $attributeCode) && $this->_isAttributeInSet($attributeCode, $product)) { $data[] = $this->_getConfiguredAttributeData($attributeCode); } } // At this point we know we are dealing with a configurable product; therefore, // this is the right place to make sure manage stock get turn off. $this->_turnOffManageStock($product); return $data; }
/** * Generate array of parameters for every container type to create html template * * @return array */ public function getDisplayOnContainers() { $container = array(); $container['anchor'] = array('label' => 'Categories', 'code' => 'categories', 'name' => 'anchor_categories', 'layout_handle' => Mage_Widget_Model_Widget_Instance::ANCHOR_CATEGORY_LAYOUT_HANDLE, 'is_anchor_only' => 1, 'product_type_id' => ''); $container['notanchor'] = array('label' => 'Categories', 'code' => 'categories', 'name' => 'notanchor_categories', 'layout_handle' => Mage_Widget_Model_Widget_Instance::NOTANCHOR_CATEGORY_LAYOUT_HANDLE, 'is_anchor_only' => 0, 'product_type_id' => ''); $container['all_products'] = array('label' => 'Products', 'code' => 'products', 'name' => 'all_products', 'layout_handle' => Mage_Widget_Model_Widget_Instance::PRODUCT_LAYOUT_HANDLE, 'is_anchor_only' => '', 'product_type_id' => ''); foreach (Mage_Catalog_Model_Product_Type::getTypes() as $typeId => $type) { $container[$typeId] = array('label' => 'Products', 'code' => 'products', 'name' => $typeId . '_products', 'layout_handle' => str_replace('{{TYPE}}', $typeId, Mage_Widget_Model_Widget_Instance::PRODUCT_TYPE_LAYOUT_HANDLE), 'is_anchor_only' => '', 'product_type_id' => $typeId); } return $container; }
public function getRemoteInstallationPrice($item) { $options = Mage::getModel('bundle/product_type')->getOrderOptions($item->getProduct()); $optionIds = array_keys($options['info_buyRequest']['bundle_option']); $types = Mage_Catalog_Model_Product_Type::getTypes(); $typemodel = Mage::getSingleton($types[Mage_Catalog_Model_Product_Type::TYPE_BUNDLE]['model']); $typemodel->setConfig($types[Mage_Catalog_Model_Product_Type::TYPE_BUNDLE]); $selections = $typemodel->getSelectionsCollection($optionIds, $item); $selection_map = array(); foreach ($selections->getData() as $selection) { if (!isset($selection_map[$selection['option_id']])) { $selection_map[$selection['option_id']] = array(); } $selection_map[$selection['option_id']][$selection['selection_id']] = $selection; } $chosen_skus = array(); foreach ($options['info_buyRequest']['bundle_option'] as $op => $sel) { $child_product_id = $selection_map[$op][$sel]['product_id']; } $child_product = Mage::getModel('catalog/product')->load($child_product_id); $diameterAttributeDetails = Mage::getSingleton("eav/config")->getAttribute("catalog_product", 'diameter'); $diameterOptionValue = $diameterAttributeDetails->getSource()->getOptionText($child_product->diameter); $read = Mage::getSingleton('core/resource')->getConnection('core_read'); $remoteInstallationTable = Mage::getSingleton('core/resource')->getTableName('product_remote_installation'); $query = "SELECT installation_price FROM " . $remoteInstallationTable . " WHERE size='" . $diameterOptionValue . "'"; $result = $read->query($query); $remote_data = $result->fetch(); if ($remote_data != '') { return $remote_data['installation_price']; } else { return '0.00'; } }
/** * Validate product type * * @param array $data * @return bool */ protected function _validateProductType($data) { if ($this->_isUpdate()) { return true; } if (!isset($data['type_id']) || empty($data['type_id'])) { $this->_critical('Missing "type_id" in request.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); } if (!array_key_exists($data['type_id'], Mage_Catalog_Model_Product_Type::getTypes())) { $this->_critical('Invalid product type.', Mage_Api2_Model_Server::HTTP_BAD_REQUEST); } }
public function getattributevaluefieldAction() { $result = array(); $name = $this->getRequest()->getParam('element_name'); $condition_name = $this->getRequest()->getParam('condition_name'); if ($code = $this->getRequest()->getParam('attribute_code')) { $attribute = Mage::getModel('catalog/product')->getResource()->getAttribute($code); if ($attribute && ($attribute->getFrontendInput() == 'select' || $attribute->getFrontendInput() == 'multiselect') || $code == 'product_type') { $options = array(); if ($code == 'product_type') { $attribute_options = Mage_Catalog_Model_Product_Type::getOptions(); } else { $attribute_options = $attribute->getSource()->getAllOptions(); } foreach ($attribute_options as $option) { extract($option); $options[] = "<option value=\"{$value}\">{$label}</option>"; } $current = ''; $conditions = array('<option ' . ($current == 'eq' ? 'selected="selected"' : '') . ' value="eq">' . $this->__('equal') . '</option>', '<option ' . ($current == 'neq' ? 'selected="selected"' : '') . ' value="neq">' . $this->__('not equal') . '</option>'); $result['condition'] = '<select style="width:120px" name="' . $condition_name . '">' . implode('', $conditions) . '</select>'; $result['select'] = '<select style="width: 100%; border: 0pt none; padding: 0pt;" name="' . $name . '">' . implode('', $options) . '</select>'; } } if (empty($result)) { $current = ''; $conditions = array('<option ' . ($current == 'eq' ? 'selected="selected"' : '') . ' value="eq">' . $this->__('equal') . '</option>', '<option ' . ($current == 'neq' ? 'selected="selected"' : '') . ' value="neq">' . $this->__('not equal') . '</option>', '<option ' . ($current == 'gt' ? 'selected="selected"' : '') . ' value="gt">' . $this->__('greater than') . '</option>', '<option ' . ($current == 'lt' ? 'selected="selected"' : '') . ' value="lt">' . $this->__('less than') . '</option>', '<option ' . ($current == 'gteq' ? 'selected="selected"' : '') . ' value="gteq">' . $this->__('greater than or equal to') . '</option>', '<option ' . ($current == 'lteq' ? 'selected="selected"' : '') . ' value="lteq">' . $this->__('less than or equal to') . '</option>', '<option ' . ($current == 'like' ? 'selected="selected"' : '') . ' value="like">' . $this->__('like') . '</option>', '<option ' . ($current == 'nlike' ? 'selected="selected"' : '') . ' value="nlike">' . $this->__('not like') . '</option>'); $result['condition'] = '<select style="width:120px" name="' . $condition_name . '">' . implode('', $conditions) . '</select>'; $result['select'] = '<input style="width:100%;border:0;padding:0;" type="text" class="input-text" name="' . $name . '" value=""/>'; } $this->getResponse()->setBody(Zend_Json::encode($result)); }
public static function getTypes() { if (is_null(self::$_types)) { self::$_types = Mage::getConfig()->getNode('global/catalog/product/type')->asArray(); } return self::$_types; }
/** * Return composite product type Ids * * @return array */ public static function getCompositeTypes() { if (is_null(self::$_compositeTypes)) { self::$_compositeTypes = array(); $types = self::getTypes(); foreach ($types as $typeId => $typeInfo) { if (array_key_exists('composite', $typeInfo) && $typeInfo['composite']) { self::$_compositeTypes[] = $typeId; } } } return self::$_compositeTypes; }
/** * Return product types by type indexing priority * * @return array */ public static function getTypesByPriority() { if (is_null(self::$_typesPriority)) { self::$_typesPriority = array(); $a = array(); $b = array(); $types = self::getTypes(); foreach ($types as $typeId => $typeInfo) { $priority = isset($typeInfo['index_priority']) ? abs(intval($typeInfo['index_priority'])) : 0; if (!empty($typeInfo['composite'])) { $b[$typeId] = $priority; } else { $a[$typeId] = $priority; } } asort($a, SORT_NUMERIC); asort($b, SORT_NUMERIC); foreach (array_keys($a) as $typeId) { self::$_typesPriority[$typeId] = $types[$typeId]; } foreach (array_keys($b) as $typeId) { self::$_typesPriority[$typeId] = $types[$typeId]; } } return self::$_typesPriority; }
/** * @return bool true if Magento knows about the product type. * @param string $type */ public function hasProdType($type) { $types = Mage_Catalog_Model_Product_Type::getTypes(); return isset($types[$type]); }
public function assignBackendModelToAttribute(Varien_Event_Observer $observer) { $backendModel = 'weee/attribute_backend_weee_tax'; $object = $observer->getEvent()->getAttribute(); if ($object->getFrontendInput() == 'weee') { $object->setBackendModel($backendModel); if (!$object->getApplyTo()) { $applyTo = array(); foreach (Mage_Catalog_Model_Product_Type::getOptions() as $option) { if ($option['value'] == 'grouped') { continue; } $applyTo[] = $option['value']; } $object->setApplyTo($applyTo); } } }
/** * extract the first element of a dom node list make sure it is lower case * if there's no item in the DOMNodeList return the default simple product type constant value * * @param DOMNodeList $nodes * @param Mage_Catalog_Model_Product $product * @return string */ public function extractProductTypeValue(DOMNodeList $nodes, Mage_Catalog_Model_Product $product) { $value = strtolower($this->coreHelper->extractNodeVal($nodes)); $type = $this->_isValidProductType($value) ? $value : Mage_Catalog_Model_Product_Type::TYPE_SIMPLE; $product->setTypeId($type)->setTypeInstance(Mage_Catalog_Model_Product_Type::factory($product, true), true); return $type; }