如何获取Magento中可配置项的URL? [英] How to get the URL to a configurable item in Magento?
问题描述
我正在使用magento并创建一个产品查找器.有没有一种方法可以链接到可配置的项目示例: mystore.com/bedding-sheets
I am using magento and creating a product finder. Is there a way I can link to a configurable item example: mystore.com/bedding-sheets
可以说,我想发送链接的朋友是250 *250厘米我想的联系是可能的表: mystore.com/bedding-sheets?attribute496=1 (除本并非如此)
lets say I want to send a friend a link to the sheet that is 250*250cm i would think the link was maybe: mystore.com/bedding-sheets?attribute496=1 (except this is not the case)
<dl class="last">
<dt><label>Size<span class="required"> *</span></label></dt>
<dd class="last">
<select class="required-entry super-attribute-select" id="attribute496" name="super_attribute[496]">
<option value="">Choose option...</option>
<option value="4">200*200cm</option>
<option value="3">200*230cm</option>
<option value="2">200*250cm</option>
<option value="1">250*250cm</option></select>
</dd>
</dl>
有人知道是否可以创建这样的链接吗?
Anyone know if it's possible to create such a link?
修改强>因此我能够了解如何使用项添加到我的购物车的/结帐/购物车/添加产物= 47&安培;数量= 1&安培; super_attribute [496]? = 4
So i was able to find out how to add an item to my cart using /checkout/cart/add?product=47&qty=1&super_attribute[496]=4
但是我希望用户预览他们将收到的商品,而不只是将其倒入购物车中.
however I want the user to get a preview of the item they will receive, instead of just dumping it into the cart.
推荐答案
不对Magento进行更改就无法做到这一点.
It's not possible to do this without making changes to Magento.
现在假设您想预定义网址中选择框的所选选项:
Now suppose you wanted to predefine the selected options of a select box in the url:
首先,您需要覆盖块 Mage_Catalog_Block_Product_View_Options_Type_Select . (我假设您已经创建了自己的模块-我还没有,并且需要帮助,请告诉我)
First you need to overwrite the block Mage_Catalog_Block_Product_View_Options_Type_Select. (I assume that you have created your own module already - I you haven't and need help with that let me know)
为此,您需要将此条目添加到您的config.xml中:
To do this you need to add this entry to your config.xml:
<config>
<global>
<blocks>
<catalog>
<rewrite>
<product_view_options_type_select>YourCompany_YourModuleName_Product_View_Options_Type_Select</product_view_options_type_select>
</rewrite>
</catalog>
</blocks>
</global>
</config>
接着添加类 YourCompany_YourModuleName_Product_View_Options_Type_Select 其中需要延长的 Mage_Catalog_Block_Product_View_Options_Type_Select
在此类中,您现在必须覆盖函数 getValuesHtml().首先,您应该从要扩展的类中复制它.
In this class you must now overwrite the function getValuesHtml(). To start off you should copy it from the class you're extending.
在此功能中,您应该找到此foreach
:
In this function you should find this foreach
:
foreach ($_option->getValues() as $_value) {
$priceStr = $this->_formatPrice(array(
'is_percent' => ($_value->getPriceType() == 'percent') ? true : false,
'pricing_value' => $_value->getPrice(true)
), false);
$select->addOption(
$_value->getOptionTypeId(),
$_value->getTitle() . ' ' . $priceStr . ''
);
}
在此之后,您添加:
$standardValue = $this->getRequest()->getParam($_option->getid());
//Mage::log("Option Name: "$_option->getid());
$select->setValue($standardValue);
这应该做到.不幸的是我现在无法测试.因此,如果您遇到麻烦,请告诉我.
This should do it. Unfortunately I can't test this right now. So let me know if you run into troubles.
我不确定$_option->getid()
是否是您参数的正确名称.但是,如果您在上面的代码清单中为我注释掉的一行中注释,则可以尝试找出答案.
在您的Magento安装中,打开文件 var/log/system.log ,其中现在应显示您的url参数的名称.
I'm not sure if the $_option->getid()
is the right name for your parameter. But you could try to find that out if you comment in the one line I commented out for you in the code listing from above.
In your Magento installation open the file var/log/system.log where the name of your url parameters should now appear.
现在,您知道如何命名url参数了,您可以执行所需的操作: url/to/product?option_id = value_id
Now that you know the how to name the url parameters you can do exactly what you wanted: url/to/product?option_id=value_id
PS:如果您问自己为什么我们创建一个新类而不是直接在Magento核心中更改它:我们这样做是为了防止在更新到新版本的Magento时出现问题.
PS: If you ask yourself why we create a new class instead of changing it directly in the Magento core: We do this to prevent problems when updating to a new version of Magento.
希望我能帮上忙.
这篇关于如何获取Magento中可配置项的URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!