Prestashop add product error : Property Product->l

2019-08-28 07:52发布

hello i'm tring to add new product to my prestashop store using REST api , but when i send my xml request i have this response: Validation error: "Property Product->link_rewrite is empty" !!! this is my xml request :

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>

please i'm waiting for any help

2条回答
等我变得足够好
2楼-- · 2019-08-28 08:17

I got the solution. Go to classes >> controller >> AdminController.php

See the function copyFromPost

Find,

$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']];
                }
            }
        }
    }

Replace with,

$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']];
    }   
查看更多
Rolldiameter
3楼-- · 2019-08-28 08:33

The link_rewrite element is also language dependent. Try replacing:

<link_rewrite>hello</link_rewrite>

with:

<link_rewrite>
    <language id="1">hello</language>
    <language id="2">hello</language>
</link_rewrite>
查看更多
登录 后发表回答