【问题标题】:Updating Magento Product Attributes Using SKU使用 SKU 更新 Magento 产品属性
【发布时间】:2023-03-06 15:20:01
【问题描述】:

我搜索过 SO、Google 和 Magento 论坛。没有任何解决方案有帮助。

我正在尝试通过 Joomla! 更新产品的自定义属性!组件使用 Magento 的 SOAP API V1。我没有返回任何错误,实际上,我返回的结果表明更新成功。

检查 Magento 后端时,这个特定产品没有任何变化,显然是通过我的脚本更新的。

我通过 Ajax 请求发送值。值为 100%(三重检查)。该产品确实存在于 Magento 中。

我正在尝试使用产品的 SKU(数字和非数字)来执行此操作,但即使是 ID 也会给我相同的结果。

我现在的代码(我已经尝试了很多变体):

$data = trim($_REQUEST['badgedata']);
$sku = trim($_REQUEST['skudata']);

$update_data = array(
    'additional_attributes' => array(
        'single_data' => array( 
            array(
                'badge' => $data
            )
        )
    )
);

$mage_url = 'http://localhost/magentosite/index.php/api/soap?wsdl'; 
$mage_user = 'magentousername'; 
$mage_api_key = 'magentoapikey';

$soap = new SoapClient( $mage_url );

$session_id = $soap->login( $mage_user, $mage_api_key );

$update = $soap->call($session_id, 'catalog_product.update', array($sku, $update_data));

希望这是足够的信息。我错过了什么吗?

任何帮助将不胜感激!谢谢:)

【问题讨论】:

  • 尝试重新索引您的目录,它可能会解决这个问题。你清理缓存了吗?
  • 我确实做到了。当我运行这个脚本时,Magento 一直抱怨缓存和索引。所以有些事情正在发生,但我没有看到。没有任何产品受到影响:\

标签: magento attributes product


【解决方案1】:

好吧,

我在post here 的帮助下解决了这个问题。打补丁“app/code/core/Mage/Catalog/Model/Product/Api/V2.php”

第 263 行附近的某处,在:

if (property_exists($productData, 'additional_attributes')) {...}

放置第三个 IF 语句:

if (gettype($productData->additional_attributes) == 'array') {
    foreach ($productData->additional_attributes as $k => $v) {
        $_attrCode = $k;
        $productData->$_attrCode = $v;
    }
}

现在使用 V2 的 SOAP API(我一开始就应该这样做 *-.-)

新的工作代码:

$data = trim($_REQUEST['badgedata']);
$sku = trim($_REQUEST['skudata']);

$update_data = array (
    'additional_attributes' => array (
        'single_data' => array (
            array ('key' => 'badge', 'value' => $data)
        )
    )
);

$mage_url = 'http://localhost/magentosite/index.php/api/v2_soap?wsdl'; 
$mage_user = 'magentousername'; 
$mage_api_key = 'magentoapikey';

$soap = new SoapClient( $mage_url );

$session_id = $soap->login( $mage_user, $mage_api_key );

$update = $soap->catalogProductUpdate($session_id, $sku, $update_data);

感谢stroisi

【讨论】:

  • 因为我使用的是 1.9 版,所以它在不更新 v2.php 的情况下对我有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多