00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Simple extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Attributes
00035 {
00036 protected function _prepareForm()
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
00059 foreach ($attributes as $attribute) {
00060 if (($attribute->getIsRequired()
00061 && $attribute->getApplyTo()
00062
00063 && !in_array(Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE, $attribute->getApplyTo())
00064
00065 && !in_array($attribute->getId(),$this->_getProduct()->getTypeInstance(true)->getUsedProductAttributeIds($this->_getProduct())))
00066
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
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 }
00174
00175
00176
00177
00178
00179
00180 protected function _getProduct()
00181 {
00182 return Mage::registry('current_product');
00183 }
00184 } // Class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Simple End