我正在尝试将多个可配置产品添加到 Magento 1.7.2 的类别列表页面中。我正在使用 Organic Internet SCP 扩展以及 EM Gala Colorswatches,这使得这比平常更棘手。我已经按照这些网站的教程进行操作......它们的想法几乎相同......
http://www.catgento.com/adding-configurable-product-options-to-category-list-in-magento/
下拉列表和色板在产品页面上显示良好,但在类别页面上显示下拉列表、标签和价格,但在选择下拉列表时不显示产品值。我已经从它工作的产品页面中包含了所有相同的 .js 文件。我能看到的唯一区别是在控制台中我从prototype.js 收到以下错误
TypeError: document.getElementById(...) is null
element.attachEvent("ondataavailable", responder);
prototype.js (line 5644)
TypeError: element.attachEvent is not a function
element.attachEvent("ondataavailable", responder);
prototype.js (line 5644)
TypeError: element.attachEvent is not a function
element.attachEvent("on" + actualEventName, responder);
TypeError: element.dispatchEvent is not a function
element.dispatchEvent(event);
仅当我在页面上取消注释可配置产品块时,才会出现第三个错误。它所指的函数在prototype.js中,如下所示
function observe(element, eventName, handler) {
element = $(element);
var responder = _createResponder(element, eventName, handler);
if (!responder) return element;
if (eventName.include(':')) {
if (element.addEventListener)
element.addEventListener("dataavailable", responder, false);
else {
element.attachEvent("ondataavailable", responder);
element.attachEvent("onlosecapture", responder);
}
} else {
var actualEventName = _getDOMEventName(eventName);
if (element.addEventListener)
element.addEventListener(actualEventName, responder, false);
else
element.attachEvent("on" + actualEventName, responder);
}
return element;
}
当我查看源代码时,我可以看到 JSON 对象在那里并且数据可用,但由于某种原因,它没有像产品页面上的选项一样被添加到选择框中...。任何帮助将不胜感激。
这是来自 app/design/frontend/default/mytheme/catalog/product/list.phtml 的代码
<?php if ($_product->getData('type_id') == "configurable"){
Mage::unregister('product');
Mage::register('product', $_product);
$block = $this->getLayout()->createBlock(
'OrganicInternet_SimpleConfigurableProducts_Catalog_Block_Product_View_Type_Configurable',
'options_configurable',
array('template' => 'catalog/product/view/type/options/configurable.phtml')
);
echo $block->toHtml();
$priceBlock = $this->getLayout()->createBlock(
'OrganicInternet_SimpleConfigurableProducts_Catalog_Block_Product_Price',
$_product->getFinalPrice(),
array('template' => 'catalog/product/price.phtml')
);
echo $priceBlock->toHtml();
}
?>
这是此块在 /app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml 调用的代码
<?php
$_product = $this->getProduct();
$_attributes = Mage::helper('core')->decorateArray($this->getAllowAttributes());
?>
<?php if ($_product->isSaleable() && count($_attributes)):?>
<dl>
<?php foreach($_attributes as $_attribute): ?>
<dt><label class="required"><!-- <em>*</em>--><?php echo $_attribute->getLabel() ?></label></dt>
<dd<?php if ($_attribute->decoratedIsLast){?> class="last"<?php }?>>
<div class="input-box">
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select_<?php echo $_product->getId()?>">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
</div>
</dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">
var spConfig_<?php echo $_product->getId()?> = new Inchoo_Product.Config(<?php echo $this->getJsonConfig() ?>);
</script>
<?php endif;?>
在此先感谢您,如果您需要更多信息,请告诉我...