Prestashop使用模块添加产品,不能强制product_id

问题描述 投票:3回答:2

正如主题所说,我在添加产品(使用产品类)时遇到问题。一切正常,但即使我指定$ product-> id = 1234;它不会使用此ID保存它,它只是在数据库中自动递增产品。但是我确实需要将自己的product_id插入数据库中(因为我是从地线数据库中导入产品的,因此需要经常对其进行更新)

这是我的代码:

$langId = (int) (Configuration::get('PS_LANG_DEFAULT'));
$p = new Product($prod['towar_id']);
$p->id = $prod['towar_id'];
$p->name = array($langId => $prod['nazwa']);
$p->ean13 = $prod['kod'];
$p->id_category_default = 6;
$p->category = array(6);
$p->link_rewrite = array($langId => Tools::link_rewrite($prod['nazwa']));
$p->weight = $prod['ile_kg_litrow'];
$p->quantity = $prod['magazyny']['magazyn']['stan_magazynu'];
$p->price = $prod['cena_detal'];
$p->add();

那么有什么方法可以插入我自己的产品ID?

php prestashop
2个回答
6
投票

我设法通过添加$ _GET ['forceIDs'] = 1来修复它或只是在网址末尾添加?forceIDs = 1。


0
投票

amigo,tefuncionó?哟,不,他洛格罗多·哈塞洛,我在找马诺吗?

埃斯佩德·米·科迪戈]:>

        $webService = new PrestaShopWebservice($url, $key, $debug);
        $xmlResponse = $webService->get(['url' => $url . '/api/products?schema=blank']);
        $productXML = $xmlResponse->product[0];

         // $_GET ['forceIDs'] = 1;

        // Aqui se le da valor a los campos
        // unset ($productXML->id);
        //$productXML->id =  //$clave->id_product;                                  // No se puede colocar el id, ya que es automatico
        $productXML->name->language[0] = $clave->name;                              // Nombre
        $productXML->description->language[0] = $clave->description;                // Descripción
        $productXML->description_short->language[0] = $clave->description_short;    // Descripción
        $productXML->id_manufacturer = $id_manufacturer;                            // fabricante
        $productXML->id_supplier = $clave->id_supplier;                             // Proveedor
        $productXML->id_category_default = $clave->id_category_default;             // Categoría por Defecto
        $productXML->id_tax_rules_group = $clave->id_tax_rules_group;               // Impuesto 0 sin IVA, 1 con IVA
        $productXML->reference = $clave->reference;                                 // Referencia
        $productXML->price = $clave->price;                                         // Precio
        $productXML->active = $clave->active;                                       // Activo?
        $productXML->on_sale = $clave->on_sale;                                     // en venta?
        $productXML->minimal_quantity = 1;                                          // Cantidad mínima
        $productXML->available_for_order = 1;                                       // Disponible para ordenar
        $productXML->state = $clave->state;                                         // Estado
        $productXML->stock_available = 10;                                          // Stock Disponible

        //Aquí realizamos las asignaciones de categorías
        $productXML->associations->categories->addChild('category')->addChild('id', $id_seccion);
        $productXML->associations->categories->addChild('category')->addChild('id', $id_marca);
        $productXML->associations->categories->addChild('category')->addChild('id', $id_familia);
        $productXML->associations->categories->addChild('category')->addChild('id', $id_subfamilia);

       // var_dump($productXML);

            try {
            $addedProductResponse = $webService->add([
                    'resource' => 'products',
                    'postXml' => $xmlResponse->asXML(),
                ]);
                $productXML = $addedProductResponse->product[0];

                var_dump($productXML);

                echo sprintf("Producto creado satisfactoriamente ID: %s", (string) $productXML->id);

            } catch (PrestaShopWebserviceException $e) {
            echo $e->getMessage();
            }
    }
© www.soinside.com 2019 - 2024. All rights reserved.