只是为了解释一些事情,假设您希望产品页面上有一个链接,该链接以特定配置的方式将产品添加到购物车。例如,让我们使用“T 恤”的旧备用。属性可能有颜色和大小。还假设您销售具有尺寸和颜色的“裤子”,但您希望用户能够使用裤子的下拉菜单并有 T 恤的按钮。
按钮将预先配置,裤子将允许任何选择
您将在 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;?>
并用这样的东西替换它
<?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);
}
?>
此代码未经测试。我在运行中对其进行了编码,并且我坚信这是找到一个好的解决方案的良好基础!祝你好运。