Magento自定义选项-在自定义选项字段中添加CSS className [英] Magento Custom Options - add a CSS className to the custom option field

查看:107
本文介绍了Magento自定义选项-在自定义选项字段中添加CSS className的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想指定一个CSS类以应用于我的自定义选项字段.这将使我能够在产品视图页面上使用更强大的JavaScript选择器.

I want to specify a CSS class to apply to my custom options fields. This will allow me to use more robust JavaScript selectors on the product view page.

因此在Admin的Product> Custom选项中,我想要这样的内容:

So in Product>Custom options in the Admin I want to have something like this:

我在其中将CSS Class属性添加到该字段的位置.

Where I've added the CSS Class attribute to the field.

可以在adminhtml模板文件中添加足够的内容:

This can be added simply enough in the adminhtml template file:

app\design\adminhtml\default\default\template\catalog\product\edit\options\option.phtml

但是我不知道我需要覆盖/扩展哪些文件才能在单击保存"时使其保存该额外属性. 谁能指出我正确的方向?

But I don't know which files I need to override/extend in order to get it saving that extra attribute when I click Save. Can anyone point me in the right direction?

推荐答案

假定您对选项类型文本"执行此操作.您需要提供一种输入,编辑,存储和输出此新属性的方法.

Assuming you do this for the option type "text". You need to provide a way to enter, edit, store, and output this new property.

要输入:如您所知,您必须编辑后端模板文件. app \ design \ adminhtml \ default \ default \ template \ catalog \ product \ edit \ options \ type \ text.phtml:

To Enter: As you have already found out, you must edit the backend template files. app\design\adminhtml\default\default\template\catalog\product\edit\options\type\text.phtml:

这将添加一个字段以输入自定义CSS类.

this will add a field to enter the custom css class to.

要编辑:您需要重写一个输出选项HTML的块,以便新字段可以从模型中获取值.在模块中创建一个声明如下的块:

To Edit: You need to rewrite a block that outputs option HTML, so that the new field can get a value from the model. Create a block in your module that is declared as follows:

class YourPackage_YourModule_Block_Adminhtml_Option extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option 
{

从类Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option复制/粘贴函数getOptionValues()并添加代码

Copy/paste the function getOptionValues() from class Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Options_Option and add the code

##.......code omitted for brevity.......##
$value['sku'] = $this->htmlEscape($option->getSku());
$value['max_characters'] = $option->getMaxCharacters();

// your new field output to the adminhtml form
$value['custom_css'] = $option->getCustomCss();

$value['file_extension'] = $option->getFileExtension();
##.......code omitted  for brevity.......##

要存储.这有点棘手.您需要扩展表catalog_product_option;.其中一栏用于存储新属性.创建具有以下内容的安装/更新脚本:

To Store. This is a bit tricky. You need to extend the table catalog_product_option; with one column to store your new property in. Create an install/update script with the following content:

$installer = $this;
$installer->startSetup();
$installer->run("
    ALTER TABLE `catalog_product_option` ADD
    `custom_css` text");
$installer->endSetup();

运行脚本后,确保表具有新列custom_css

After the script is run, make sure the table has a new column custom_css

要输出:最后,通过添加代码以输出新的自定义CSS类属性(如

To Output: Finally, update the template file frontend/yourpackage/yourtheme/template/catalog/product/view/options/type/text.phtml by adding a code to output your new custom CSS class property, something like

$_option->getCustomCss();

这篇关于Magento自定义选项-在自定义选项字段中添加CSS className的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆