Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Simple Class Reference

Inheritance diagram for Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Simple:

Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes Mage_Adminhtml_Block_Catalog_Form Mage_Adminhtml_Block_Widget_Form Mage_Adminhtml_Block_Widget Mage_Adminhtml_Block_Template Mage_Core_Block_Template Mage_Core_Block_Abstract Varien_Object

List of all members.

Protected Member Functions

 _prepareForm ()
 _getProduct ()


Detailed Description

Definition at line 34 of file Simple.php.


Member Function Documentation

_getProduct (  )  [protected]

Retrieve currently edited product object

Returns:
Mage_Catalog_Model_Product

Definition at line 180 of file Simple.php.

00181     {
00182         return Mage::registry('current_product');
00183     }

_prepareForm (  )  [protected]

Prepare form before rendering HTML

Returns:
Mage_Adminhtml_Block_Widget_Form

Initialize product object as form property for using it in elements generation

Add new attribute button if not image tab

Set attribute default values for new product

Reimplemented from Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes.

Definition at line 36 of file Simple.php.

00037     {
00038         $form = new Varien_Data_Form();
00039 
00040         $form->setFieldNameSuffix('simple_product');
00041 
00042         $fieldset = $form->addFieldset('simple_product', array(
00043             'legend' => Mage::helper('catalog')->__('Quick simple product creation')
00044         ));
00045         $this->_addElementTypes($fieldset);
00046         $attributesConfig = array(
00047             'autogenerate' => array('name', 'sku'),
00048             'additional'   => array('name', 'sku', 'visibility', 'status')
00049         );
00050 
00051         $availableTypes = array('text', 'select', 'multiselect', 'textarea', 'price');
00052 
00053         $attributes = Mage::getModel('catalog/product')
00054             ->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
00055             ->setAttributeSetId($this->_getProduct()->getAttributeSetId())
00056             ->getAttributes();
00057 
00058         /* Standart attributes */
00059         foreach ($attributes as $attribute) {
00060             if (($attribute->getIsRequired()
00061                 && $attribute->getApplyTo()
00062                 // If not applied to configurable
00063                 && !in_array(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, $attribute->getApplyTo())
00064                 // If not used in configurable
00065                 && !in_array($attribute->getId(),$this->_getProduct()->getTypeInstance(true)->getUsedProductAttributeIds($this->_getProduct())))
00066                 // Or in additional
00067                 || in_array($attribute->getAttributeCode(), $attributesConfig['additional'])) {
00068 
00069                 $inputType = $attribute->getFrontend()->getInputType();
00070                 if (!in_array($inputType, $availableTypes)) {
00071                     continue;
00072                 }
00073                 $attributeCode = $attribute->getAttributeCode();
00074                 $element = $fieldset->addField(
00075                     'simple_product_' . $attributeCode,
00076                      $inputType,
00077                      array(
00078                         'label'    => $attribute->getFrontend()->getLabel(),
00079                         'name'     => $attributeCode,
00080                         'required' => $attribute->getIsRequired(),
00081                      )
00082                 )->setEntityAttribute($attribute);
00083 
00084                 if (in_array($attributeCode, $attributesConfig['autogenerate'])) {
00085                     $element->setDisabled('true');
00086                     $element->setValue($this->_getProduct()->getData($attributeCode));
00087                     $element->setAfterElementHtml(
00088                          '<input type="checkbox" id="simple_product_' . $attributeCode . '_autogenerate" '
00089                          . 'name="simple_product[' . $attributeCode . '_autogenerate]" value="1" '
00090                          . 'onclick="toggleValueElements(this, this.parentNode)" checked="checked" /> '
00091                          . '<label for="simple_product_' . $attributeCode . '_autogenerate" >'
00092                          . Mage::helper('catalog')->__('Autogenerate')
00093                          . '</label>'
00094                     );
00095                 }
00096 
00097 
00098                 if ($inputType == 'select' || $inputType == 'multiselect') {
00099                     $element->setValues($attribute->getFrontend()->getSelectOptions());
00100                 }
00101             }
00102 
00103         }
00104 
00105         /* Configurable attributes */
00106         foreach ($this->_getProduct()->getTypeInstance(true)->getUsedProductAttributes($this->_getProduct()) as $attribute) {
00107             $attributeCode =  $attribute->getAttributeCode();
00108             $fieldset->addField( 'simple_product_' . $attributeCode, 'select',  array(
00109                 'label' => $attribute->getFrontend()->getLabel(),
00110                 'name'  => $attributeCode,
00111                 'values' => $attribute->getSource()->getAllOptions(true, true),
00112                 'required' => true,
00113                 'class'    => 'validate-configurable',
00114                 'onchange' => 'superProduct.showPricing(this, \'' . $attributeCode . '\')'
00115             ));
00116 
00117             $fieldset->addField('simple_product_' . $attributeCode . '_pricing_value', 'hidden', array(
00118                 'name' => 'pricing[' . $attributeCode . '][value]'
00119             ));
00120 
00121             $fieldset->addField('simple_product_' . $attributeCode . '_pricing_type', 'hidden', array(
00122                 'name' => 'pricing[' . $attributeCode . '][is_percent]'
00123             ));
00124         }
00125 
00126         /* Inventory Data */
00127         $fieldset->addField('simple_product_inventory_qty', 'text', array(
00128             'label' => Mage::helper('catalog')->__('Qty'),
00129             'name'  => 'stock_data[qty]',
00130             'class' => 'validate-number',
00131             'required' => true,
00132             'value'  => 0
00133         ));
00134 
00135         $fieldset->addField('simple_product_inventory_is_in_stock', 'select', array(
00136             'label' => Mage::helper('catalog')->__('Stock Availability'),
00137             'name'  => 'stock_data[is_in_stock]',
00138             'values' => array(
00139                 array('value'=>1, 'label'=> Mage::helper('catalog')->__('In Stock')),
00140                 array('value'=>0, 'label'=> Mage::helper('catalog')->__('Out of Stock'))
00141             ),
00142             'value' => 1
00143         ));
00144 
00145         $stockHiddenFields = array(
00146             'use_config_min_qty'            => 1,
00147             'use_config_min_sale_qty'       => 1,
00148             'use_config_max_sale_qty'       => 1,
00149             'use_config_backorders'         => 1,
00150             'use_config_notify_stock_qty'   => 1,
00151             'is_qty_decimal'                => 0
00152         );
00153 
00154         foreach ($stockHiddenFields as $fieldName=>$fieldValue) {
00155             $fieldset->addField('simple_product_inventory_' . $fieldName, 'hidden', array(
00156                 'name'  => 'stock_data[' . $fieldName .']',
00157                 'value' => $fieldValue
00158             ));
00159         }
00160 
00161 
00162         $fieldset->addField('create_button', 'note', array(
00163             'text' => $this->getButtonHtml(
00164                 Mage::helper('catalog')->__('Quick Create'),
00165                 'superProduct.quickCreateNewProduct()',
00166                 'save'
00167             )
00168         ));
00169 
00170 
00171 
00172         $this->setForm($form);
00173     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:22:45 2009 for Magento by  doxygen 1.5.8