我们的网站上有一个工作扩展,允许客户请求样品 - 我们类别页面上的代码是:
<?php if (Mage::helper('floorsamples')->isSamplesEnabled($_product->getId())): ?>
<a href="<?php echo $this->getUrl('samples/cart/add') . '?product=' . $_product->getId(); ?>" class="link-compare" onclick="sampleconfirm()"><img src="<?php echo $this->getSkinUrl('images/cat-freesample.png')?>" /></a>
<?php else: ?>
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->getSkinUrl('images/cat-moreinfo.png')?>" /></a>
<?php endif; ?>
但是,检查samples选项是否可用会导致抛出异常。除了这个例外,模块的其余部分似乎完全正常。
功能是:
public function isSamplesEnabled($productId) {
if (!$this->getConfigClass()->enabled) {
return false;
}
$product = $this->_getProduct($productId);
foreach ($product->getCategoryCollection() as $category) {
if ($this->_isSamplesEnabledHelper($product, $category)) {
return true;
}
}
return false;
}
private function _isSamplesEnabledHelper($product, $category, $recursive = false) {
$category = Mage::getModel("catalog/category")->load($category->getEntityId());
if ($this->_getData($category)) {
return true;
}
if ($recursive) {
foreach ($category->getChildrenCategories() as $child) {
if ($this->_isSamplesEnabledHelper($product, $child, $recursive)) {
return true;
}
}
}
return false;
}
谢谢!
PS。以下是日志
a:5:{i:0;s:202:"SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1";i:1;s:6240:"#0