1

请帮助在结帐时获取 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)
4

1 回答 1

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');
于 2011-08-05T11:52:06.273 回答