Prestashop添加产品错误:属性Product-> link_rewrite为空

时间:2015-01-16 10:43:47

标签: xml api prestashop product

您好我想使用REST api将新产品添加到我的prestashop商店,但是当我发送我的xml请求时,我有这样的回复:验证错误:"属性产品 - > link_rewrite为空&# 34; ! 这是我的xml请求:

xml=<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
    <id/>
    <id_manufacturer/>
    <id_supplier/>
    <id_category_default/>
    <new/>
    <cache_default_attribute/>
    <id_default_image/>
    <id_default_combination/>
    <id_tax_rules_group/>
    <type/>
    <id_shop_default/>
    <reference/>
    <supplier_reference/>
    <location/>
    <width/>
    <height/>
    <depth/>
    <weight/>
    <quantity_discount/>
    <ean13/>
    <upc/>
    <cache_is_pack/>
    <cache_has_attachments/>
    <is_virtual/>
    <on_sale/>
    <online_only/>
    <ecotax/>
    <minimal_quantity/>
    <price>1000</price>
    <wholesale_price/>
    <unity/>
    <unit_price_ratio/>
    <additional_shipping_cost/>
    <customizable/>
    <text_fields/>
    <uploadable_files/>
    <active>1</active>
    <redirect_type/>
    <id_product_redirected/>
    <available_for_order/>
    <available_date/>
    <condition/>
    <show_price/>
    <indexed/>
    <visibility/>
    <advanced_stock_management/>
    <date_add/>
    <date_upd/>
    <meta_description><language id="1"/><language id="2"/></meta_description>
    <meta_keywords><language id="1"/><language id="2"/></meta_keywords>
    <meta_title><language id="1"/><language id="2"/></meta_title>
    <link_rewrite>hello</link_rewrite>
    <name>test name</name>
    <description>test description</description>

    <available_now><language id="1"/><language id="2"/></available_now>
    <available_later><language id="1"/><language id="2"/></available_later>
<associations></associations>
</product>
</prestashop>

请我等待任何帮助

2 个答案:

答案 0 :(得分:1)

我得到了解决方案。转到课程&gt;&gt;控制器&gt;&gt; AdminController.php

查看功能 copyFromPost

查找

$languages = Language::getLanguages(false);
$class = get_class($object);
    $fields = $class->$definition['fields'];

    foreach ($fields as $field => $params) {
        if (array_key_exists('lang', $params) && $params['lang']) {
            foreach ($languages as $language) {
                if (isset($_POST[$field.'_'.(int)$language['id_lang']])) {
                    $object->{$field}[(int)$language['id_lang']] = $_POST[$field.'_'.(int)$language['id_lang']];
                }
            }
        }
    }

替换为,

$rules = call_user_func(array(get_class($object), 'getValidationRules'), get_class($object));
    if (count($rules['validateLang']))
    {
        $languages = Language::getLanguages(false);
        foreach ($languages as $language)
            foreach (array_keys($rules['validateLang']) as $field)
                if (isset($_POST[$field.'_'.(int)$language['id_lang']]))
                    $object->{$field}[(int)$language['id_lang']] = $_POST[$field.'_'.(int)$language['id_lang']];
    }   

答案 1 :(得分:1)

link_rewrite元素也依赖于语言。尝试更换:

<link_rewrite>hello</link_rewrite>

使用:

<link_rewrite>
    <language id="1">hello</language>
    <language id="2">hello</language>
</link_rewrite>