0
アイテムIDを使用してカートアイテムを更新するには?私は多くのことを探索したが、成功できなかった、ここに私のコードでいる -Magento - アイテムIDでアイテムを更新する
require_once '../app/Mage.php';
Mage::app('default');
$qty = $_REQUEST['quantity'];
$item_id = (int) $_REQUEST['item_id'];
$cart = Mage::getSingleton('checkout/cart');
$quoteItem = $cart->getQuote()->getItemById($item_id);
/*$quoteItem = Mage::getModel('sales/quote_item')->getCollection()
->addFieldToFilter('item_id', array('in' => array($item_id)));*/
print_r($quoteItem);
if (!$quoteItem) {
Mage::throwException('Quote item is not found.');
}
if ($qty == 0) {
$cart->removeItem($id);
} else {
$quoteItem->setQty($qty)->save();
}
$cart->save();
私はしかし、同じコードがwebsite.Pleaseヘルプで正常に動作している、APIでそれを実装しています!
ウェブサービスでコードを使用していますが、ここでは「セッション」が有効でしょうか? –
致命的なエラー:行13の/home/yxyshareoflovest/public_html/web-services/test.phpの非オブジェクト上のメンバー関数getEvent()を呼び出す –
@SachinVairagi以下の行を削除します。 $ quote = $ observer-> getEvent() - > getQuote(); var_dump($ quote-> getId()); これはオブザーバでのみ機能します。 –