结帐时获取magento属性的麻烦

时间:2011-08-05 11:46:20

标签: magento attributes checkout

帮助请在checkbout时获取magento属性。我有'only_registered'属性。我试图通过这段代码获取属性:

$cart = Mage::getSingleton('checkout/session')->getQuote()->getAllVisibleItems();
foreach ($cart as $_item){
  $_product = Mage::getModel('catalog/product')->load($_item->getProduct());
  $registeredonly = $_product->getRegisteredOnly();
}

但此代码会产生magento错误。

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:4723:"#0 /work/www/topps.loc/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)

1 个答案:

答案 0 :(得分:2)

我可以在代码中看到以下错误:

$_product = Mage::getModel('catalog/product')->load($_item->getProduct());

应该是:

$_product = Mage::getModel('catalog/product')->load($_item->getProductId());

我看到你说变量名称是'only_registered'所以你应该通过以下方式访问它:

$registeredonly = $_product->getOnlyRegistered();

如果这不起作用,只需:

$registeredonly = $_product->getData('only_registered');