我想扩展Magento的自定义选项功能。我不能使用任何现有的,如sku或title。我需要一个全新的,称为“路径”。添加它的步骤是什么?似乎在catalog_product_option中添加一行是其中的一部分,但我认为还有很多工作要做?
答案 0 :(得分:0)
我过去做过一些非常简单的事情,你可能会或可能不会觉得有用。我们的情况是需要在新文本选项中使用“自动完成”字段。所以在design \ adminhtml \ default \ default \ template \ catalog \ product \ edit \ options \ type \ text.phtml中,这是OptionTemplateText的新javascript var:
OptionTemplateText = '<table class="border" cellpadding="0" cellspacing="0">'+
'<tr class="headings">'+
'<th class="type-price"><?php echo Mage::helper('catalog')->__('Price') ?></th>'+
'<th class="type-type"><?php echo Mage::helper('catalog')->__('Price Type') ?></th>'+
'<th class="type-sku"><?php echo Mage::helper('catalog')->__('SKU') ?></th>'+
'<th class="type-last last"><?php echo Mage::helper('catalog')->__('Max Characters') ?> </th>'+
'<th class="type-last last"><?php echo Mage::helper('catalog')->__('Auto Complete') ?> </th>'+
'</tr>'+
'<tr>'+
'<td><input type="text" class="input-text validate-number product-option-price" id="product_option_{{option_id}}_price" name="product[options][{{option_id}}][price]" value="{{price}}"></td>'+
'<td><?php echo $this->getPriceTypeSelectHtml() ?>{{checkboxScopePrice}}</td>'+
'<td><input type="text" class="input-text" name="product[options][{{option_id}}][sku]" value="{{sku}}"></td>'+
'<td class="type-last last"><input type="text" class="input-text validate-zero-or-greater" name="product[options][{{option_id}}][max_characters]" value="{{max_characters}}"></td>'+
'<td class="type-last last"><input type="text" class="input-text" name="product[options][{{option_id}}][auto_complete]" value="{{auto_complete}}"> * service URL</td>'+
'</tr>'+
'</table>';
然后我们使用这个重写用我们自己的快速类覆盖了Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option:
<global>
<blocks>
<adminhtml>
<rewrite>
<catalog_product_edit_tab_options_option>MyNameSpace_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option</catalog_product_edit_tab_options_option>
</rewrite>
</adminhtml>
</blocks>
</global>
这是整个班级。
class MyNameSpace_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option {
public function __construct() {
parent::__construct();
$this->setTemplate('catalog/product/edit/options/option.phtml');
}
public function getOptionValues() {
$optionsArr = array_reverse($this->getProduct()->getOptions(), true);
if (!$this->_values) {
$values = array();
$scope = (int) Mage::app()->getStore()->getConfig(Mage_Core_Model_Store::XML_PATH_PRICE_SCOPE);
foreach ($optionsArr as $option) {
/* @var $option Mage_Catalog_Model_Product_Option */
$this->setItemCount($option->getOptionId());
$value = array();
$value['id'] = $option->getOptionId();
$value['item_count'] = $this->getItemCount();
$value['option_id'] = $option->getOptionId();
$value['title'] = $this->htmlEscape($option->getTitle());
$value['type'] = $option->getType();
$value['is_require'] = $option->getIsRequire();
$value['sort_order'] = $option->getSortOrder();
if ($this->getProduct()->getStoreId() != '0') {
$value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'title', is_null($option->getStoreTitle()));
$value['scopeTitleDisabled'] = is_null($option->getStoreTitle())?'disabled':null;
}
if ($option->getGroupByType() == Mage_Catalog_Model_Product_Option::OPTION_GROUP_SELECT) {
$i = 0;
$itemCount = 0;
foreach ($option->getValues() as $_value) {
/* @var $_value Mage_Catalog_Model_Product_Option_Value */
$value['optionValues'][$i] = array(
'item_count' => max($itemCount, $_value->getOptionTypeId()),
'option_id' => $_value->getOptionId(),
'option_type_id' => $_value->getOptionTypeId(),
'title' => $this->htmlEscape($_value->getTitle()),
'price' => $this->getPriceValue($_value->getPrice(), $_value->getPriceType()),
'price_type' => $_value->getPriceType(),
'sku' => $this->htmlEscape($_value->getSku()),
'sort_order' => $_value->getSortOrder(),
);
if ($this->getProduct()->getStoreId() != '0') {
$value['optionValues'][$i]['checkboxScopeTitle'] = $this->getCheckboxScopeHtml($_value->getOptionId(), 'title', is_null($_value->getStoreTitle()), $_value->getOptionTypeId());
$value['optionValues'][$i]['scopeTitleDisabled'] = is_null($_value->getStoreTitle())?'disabled':null;
if ($scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
$value['optionValues'][$i]['checkboxScopePrice'] = $this->getCheckboxScopeHtml($_value->getOptionId(), 'price', is_null($_value->getstorePrice()), $_value->getOptionTypeId());
$value['optionValues'][$i]['scopePriceDisabled'] = is_null($_value->getStorePrice())?'disabled':null;
}
}
$i++;
}
} else {
$value['price'] = $this->getPriceValue($option->getPrice(), $option->getPriceType());
$value['price_type'] = $option->getPriceType();
$value['sku'] = $this->htmlEscape($option->getSku());
$value['max_characters'] = $option->getMaxCharacters();
$value['auto_complete'] = $option->getAutoComplete();
$value['file_extension'] = $option->getFileExtension();
$value['image_size_x'] = $option->getImageSizeX();
$value['image_size_y'] = $option->getImageSizeY();
if ($this->getProduct()->getStoreId() != '0' && $scope == Mage_Core_Model_Store::PRICE_SCOPE_WEBSITE) {
$value['checkboxScopePrice'] = $this->getCheckboxScopeHtml($option->getOptionId(), 'price', is_null($option->getStorePrice()));
$value['scopePriceDisabled'] = is_null($option->getStorePrice())?'disabled':null;
}
}
$values[] = new Varien_Object($value);
}
$this->_values = $values;
}
return $this->_values;
}
}
这个难题的最后一块是这个小小的sql语句:
ALTER TABLE `catalog_product_option` ADD COLUMN `auto_complete` VARCHAR(255) NULL DEFAULT NULL AFTER `max_caharacters`;