我想更新number_of_download_bougt。那么SQL将如何在控制器中? 我写道:
public function updatedownloadAction($db_magento, $id, $numberdownload)
{
// $id = $this->getRequest()->getParam('id', 0);
$db_magento = Mage::getModel('downloadable/link_purchased_item')->load($id);
$db_magento->query("UPDATE downloadable_link_purchased_item d
SET d.number_of_downloads_bought = '$numberdownload'
WHERE d.item_id = '$id'");
}
但是错误
答案 0 :(得分:0)
使用setNumberOfDownloadsUsed函数设置购买的数量。
$id = $this->getRequest()->getParam('id', 0);
$linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
$linkPurchasedItem->setNumberOfDownloadsUsed($linkPurchasedItem->getNumberOfDownloadsUsed()+1);
if ($linkPurchasedItem->getNumberOfDownloadsBought() != 0 &&
!($linkPurchasedItem->getNumberOfDownloadsBought() - $linkPurchasedItem->getNumberOfDownloadsUsed())) {
$linkPurchasedItem->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED);
}
$linkPurchasedItem->save();