使用url将可配置产品添加到购物车 [英] Add a configurable product to the cart using url
问题描述
我正在尝试使用url参数将可配置的产品添加到购物车,但是我仍然收到请指定产品的选项".当我尝试使用url将产品添加到购物车时:
I'm attempting to add a configurable product to the cart using the url parameters but I'm still getting a "Please specify the product's option(s)." when I try to add a product to the cart using the url:
/myConfigurableProduct.html?options=cart&product=6&related_product=&super_attribute[146]=60&super_attribute[147]=67&super_attribute[145]=57&super_attribute[144]=49&super_attribute[148]=69&super_attribute[149]=75&super_attribute[150]=80&qty=1
我已经浏览了Magento文档,找到了解决方案,发现可以使用/cart/add?
从购物车页面中完成此操作,但是我正在尝试从产品视图页面中执行此操作.
I've looked through the Magento docs for a solution to this and found that this can be done from the cart page using the /cart/add?
, but I'm trying to do it from the product view page.
使用表单提交时,所选择的URL super_attributes不会显示错误,但是在使用url时会失败.我在这里想念什么吗?
The url super_attributes selected don't show a error when submitted using the form, but fails when using the url. Am I missing something here?
推荐答案
仅出于解释某些原因,假设您想要产品页面上的链接,该链接以特定配置的方式将产品添加到购物车.例如,让我们使用"T恤"的旧备用件.属性可能有颜色和大小.假设您销售的是具有尺寸和颜色的裤子",但您希望用户能够使用下拉菜单中的裤子并具有T恤按钮.
Just for sake of explaining some things, lets say you want a link on your product page that adds the product to the cart in a specifically configured way. For example, lets use the old standby of a "T-Shirt". There can probably be color and size for attributes. Lets also say you sell "Pants" that have a size and color, but you want the user to be able to use the dropdowns for pants and have buttons for T-Shirts.
按钮将被预先配置,裤子将允许任何选择
The buttons would be pre-configured, and the pants would allow any choice
您将在app/designt/frontend/YOURTHEME/default/template/catalog/product/view.phtml
You would do the following in the app/designt/frontend/YOURTHEME/default/template/catalog/product/view.phtml
寻找
<?php if ($_product->isSaleable() && $this->hasOptions()):?>
<?php echo $this->getChildChildHtml('container2', '', true, true) ?>
<?php endif;?>
并用类似这样的内容替换
and replace it with something like this
<?php
if ($_product->isSaleable() && $this->hasOptions())
{
$attSetName = "TSHIRT";
$product = Mage::registry('current_product');
$attributeSetModel = Mage::getModel("eav/entity_attribute_set");
$attributeSetModel->load($product->getAttributeSetId());
$attributeSetName = $attributeSetModel->getAttributeSetName();
// Its only going to work on Tshirts that are configurable products
// All others (PANTS) will fall to the default magento functionality
if (strtoupper($attributeSetName)== $attSetName && $product->getTypeId() == "configurable")
{
// Here is where you will add the cart links to set up products directly to the cart
// It *MAY* make more sense to set these up as custom variables, but for simplicity's sake, lets just hard code them in here for now
$productA = "/?super_attribute[146]=60&super_attribute[147]=67&super_attribute[145]=57&super_attribute[144]=49&super_attribute[148]=69&super_attribute[149]=75&super_attribute[150]=80&qty=1";
$productB = "/?super_attribute[146]=60&super_attribute[147]=67&super_attribute[145]=57&super_attribute[144]=49&super_attribute[148]=69&super_attribute[149]=75&super_attribute[150]=80&qty=1";
echo '<div id="YOURATTRIBUTESETNAMEcustomProducst">';
echo '<a href="/checkout/cart/add/product/' . $_product->getId() . $productA . '" />Buy Custom Option A</a>';
echo '<a href="/checkout/cart/add/product/' . $_product->getId() . $productB . '" />Buy Custom Option B</a>';
echo '</div>';
}
}
else
{
// Do the default magento action
// *not sure if container1 or container2. Each section does its own thing so
// just experiment. Mine was container2
echo $this->getChildChildHtml('container2', '', true, true);
}
?>
此代码未经测试.我即时对其进行了编码,我坚信找到良好的解决方案是一个坚实的基础!祝你好运.
This code is untested. I coded it up on the fly, and I believe strongly that it is a sound base to find a good solution! GOOD LUCK.
这篇关于使用url将可配置产品添加到购物车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!