【问题标题】:Magento API SOAP - add product with custom options to cartMagento API SOAP - 将带有自定义选项的产品添加到购物车
【发布时间】:2023-04-02 18:05:02
【问题描述】:

我正在尝试使用 SOAP v1 cart_product.add 添加具有自定义选项的产品

  • 产品 ID = 1497
  • 数量 = 1
  • 商店 ID = 2
  • 选项 ID = 2296(类型 = 文本字段)
  • 选项值 = 10001
  • 是必需的 = TRUE

一切正常,但仍然报错致命错误:未捕获的 SoapFault 异常:[1022] 请指定产品所需的选项。

这是PHP代码

$shoppingCartIncrementId = $proxy->call( $sessionId, 'cart.create',array( 2 ));

$arrProducts = array(
        'product_id' => '1497',
        'quantity' => 1,
        'options' => array ( 
                0 => array(
                        'key' =>  2296,
                        'value' =>  '1001'
                    )
                 )

);


print "<pre>";
print_r($arrProducts);
print "</pre>";


$resultCartProductAdd = $proxy->call(
$sessionId,
"cart_product.add",
array(
    $shoppingCartIncrementId,
    array($arrProducts),
    2
)
);

这是我的数组结果看起来像:

Array
(
    [product_id] => 1497
    [quantity] => 1
    [options] => Array
        (
            [0] => Array
                (
                    [key] => 2296
                    [value] => 1001
                )

        )

)

我错过了什么吗?我的数组正确吗?

请帮忙, 谢谢

【问题讨论】:

    标签: api magento soap


    【解决方案1】:

    在深入研究核心文件后,我发现了问题和一个简单的修补方法。

    问题在于“cart_product.add”/“shoppingCartProductAdd”的 SOAP API 接受一系列产品选项和带有关键“选项”的超级属性,正如您在上面所做的那样,但准备产品的代码要添加到购物车,则使用键“super_attribute”查找此信息。为了打补丁,我只是将“options”数组复制到 cart_product.add api 中的“super_attribute”数组中。

    我把补丁文件放在这里可能会有所帮助:https://github.com/mezzi/magento-api-patches/blob/master/0001-fix-soap-api-configurable-product-options.patch

    【讨论】:

      【解决方案2】:

      经过大量摆弄和阅读其他帖子后,我发现以下内容适用于 Magento 1.8 和 SOAP v1 中的自定义产品(下面 Mezzi 建议的“super_attribute”修复似乎不再有效):

      $arrProducts[$j] = 
              array (
              'product_id' => "$productID",
              'quantity' => "$quantity_item",
              'options' => 
              array (
              $option_ID => $option_value)
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多