/** * 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; } }
/** * 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; }
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(); }
/** * 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); } }
/** * @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; }
/** * 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; }
public function testGetTypes() { $types = Mage_Catalog_Model_Product_Type::getTypes(); $this->assertArrayHasKey(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE, $types); $this->assertArrayHasKey(Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL, $types); $this->assertArrayHasKey(Mage_Catalog_Model_Product_Type::TYPE_GROUPED, $types); $this->assertArrayHasKey(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, $types); $this->assertArrayHasKey(Mage_Catalog_Model_Product_Type::TYPE_BUNDLE, $types); $this->assertArrayHasKey(Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE, $types); foreach ($types as $type) { $this->assertArrayHasKey('label', $type); $this->assertArrayHasKey('model', $type); $this->assertArrayHasKey('composite', $type); // possible bug: index_priority is not defined for each type } }
/** * 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'; } }
/** * @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 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; }
protected function _getProductTypes() { return Mage_Catalog_Model_Product_Type::getTypes(); }