0
お客様に対して(プログラムによって)商品を追加していますが、「商品を見積もりに追加するリクエストが無効です」というエラーが表示されます。私はシンプルな製品(カスタムオプション付き)と設定可能な製品の両方を持っています。以下は私のコードです。助けてください。事前に多くの感謝。カスタムオプションを使用してプログラムでカートに追加
public function addtocartAction(){
try {
$cusId = $this->getRequest()->getParam('cusId');
$customer = Mage::getModel('customer/customer')->load($cusId);
$quote = Mage::getModel('sales/quote')->loadByCustomer($customer);
$quoteId = $quote->getId();
//$products = $this->getRequest()->getParam('products');
$products = json_decode('[{"proId": "906","proQty": "1", "options":{"17":"wq","16":"18"}}]');
foreach($products as $product) {
/*if (!$product->getId()) {
throw new Exception();
}*/
foreach ($product->options as $optKey => $optValue) {
$optAll[$optKey] = $optValue;
}
$mainProduct = Mage::getModel('catalog/product')->load($product->proId);
$params = array(
'product' => $product->proId,
'qty' => $product->proQty,
'options' => $optAll
);
echo "<pre />"; print_r($params);
$quote->addProduct($mainProduct, $params);
$quote->setIsActive(1);
$quote->collectTotals()->save();
}
$rslt['success'] = '1';
$rslt['message'] = 'Product has been succefully added to cart';
}
catch(Exception $e){
$rslt['success'] = '0';
$rslt['message'] = $e->getMessage();
}
print_r(json_encode($rslt));
}
ありがとうトン。このコードは単純な製品でのみ動作します。構成可能な製品でも同様に機能させるにはどうしたらいいですか?構成可能なエラーを表示しようとしているときに「製品のオプションを指定してください」と表示されます。 –
属性とその値を指定して** in super_attribute **オプションを使用する必要があります。例えば:=> 8 '$ paramsは=配列( '製品' => $製品 - > proId、 'super_attribute' =>配列( 132 => 3、 133)、 '数量' => $ product-> proQty、 ); '133,132はattribute_idsであり、3,8は属性値です。 –