如何将产品大小从XML插入MySQL? prestashop有什么功能吗?我正在尝试使用addProductAttribute,但它已被弃用。 也许generateMultipleCombinations?我希望你能帮助我。
这是我的代码:
的
的function query_attribute($xmlNode, $attr_name, $attr_value) {
foreach($xmlNode as $node) {
switch($node[$attr_name]) {
case $attr_value:
return $node;
}
}
}
include dirname(__FILE__) . '/../config/config.inc.php';
include dirname(__FILE__) . '/../init.php';
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
$xmlstr = file_get_contents('......xml');
$xml = new SimpleXMLElement($xmlstr);
foreach($xml->products->product as $p)
{
$desc = (!empty($p->description))?strip_tags($p->description):'...';
$catid = intval($p->category_id);
$kateg = $kategorie[$catid];
$product = new Product();
$product->ean13 = $p['product_id'];
$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $p->name);
$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') => $p['product_id']);
$product->description = array((int)Configuration::get('PS_LANG_DEFAULT') => $desc);
$product->id_category = $kateg;
$product->id_category_default = $kateg;
$product->redirect_type = '404';
$product->price = $p->price_netto;
//$product->quantity = 1;
$product->minimal_quantity = 1;
$product->show_price = 1;
$product->on_sale = 1;
$product->online_only = 1;
$product->meta_keywords = '';
$product->is_virtual=0;
$product->manufacturer_name=$p->producer;
$product->add();
StockAvailable::setQuantity($p['product_id'], 0, (int) 1);
$product->addToCategories(array($kateg));
$default = 1;
foreach ($p->sizes->size as $size) {
$quantity = $size['count'];
Db::getInstance()->execute("INSERT INTO `ps_attribute_impact` (`id_attribute_impact`, `id_product`, `id_attribute`, `weight`, `price`) VALUES (NULL, '{$product->id}', '{$rozmiary[$size['name']]}', '0', '0');", false);
//$combinationID = $product->addAttribute($p->price_netto, 0, 1, 0, $quantity, 'aa', '', $default);
//addAttribute($price, $weight, $unit_impact, $ecotax, $id_images, $reference, $ean13, $default, $location = null, $upc = null, $minimal_quantity = 1, array $id_shop_list = array(), $available_date = null)
$default = 0;
}
的
在我的XML中看起来像: 的 的
的<sizes>
<size name="S" count="4" />
<size name="M" count="1" />
<size name="L" count="4" />
</sizes>
的