public function utilHtmlDefaultPrice() { $defaultPriceValue = GlobalConfig::getDefaultPrice(); $selectOptions = ""; for ($i = 1; $i <= 5; $i++) { $isSelected = $i == $defaultPriceValue ? "selected" : ""; $selectOptions .= "<option value='" . $i . "' " . $isSelected . ">" . $this->l('Price') . " " . $i . "</option>"; } $html = '<select name="osi_default_price" style="width:360px">' . $selectOptions . '</select>'; return $html; }
public static function createProductXml($product, $isMainProduct = true, $attributesMap, $featuresMap, $productChildInfos) { $docXml = self::createResponseXml(); $request = $docXml->createElement("request"); $ProductElem = $docXml->createElement("Article"); $ProductElem->setAttribute('Reference', trim($product['reference'])); $ProductElem->setAttribute('Designation', self::cut($product['product_name'], 100)); if ($product['description_short'] != "") { $description1 = $product['description_short']; $description1 = self::convertToUTF8($description1); $ProductElem->setAttribute('Description_1', $description1); } if ($product['description'] != "") { $description2 = $product['description']; $description2 = self::convertToUTF8($description2); $ProductElem->setAttribute('Description_2', $description2); } if ($product['id_manufacturer'] != 0) { //if this Id == 0, manufacturer not exists $ProductElem->setAttribute('Marque', $product['manufacturer_name']); } if ($product['rate'] != null) { $tax = round(floatval($product['rate']), 4); } else { $tax = 0; } if ($product['price'] != null) { $ProductElem->setAttribute('Taux_Tva', $tax); if (substr(_PS_VERSION_, 0, 3) > 1.3) { /* Prestashop 1.4 */ if (!$isMainProduct) { $ht = round(floatval($product['price']) + floatval($productChildInfos['price']), 4); $ttc = round(floatval($product['price']) + $product['price'] * $tax / 100, 2) + round(floatval($productChildInfos['price']) + floatval($productChildInfos['price'] * $tax / 100), 2); } else { $ht = round(floatval($product['price']), 4); $ttc = round(floatval($ht + $ht * $tax / 100), 4); } } else { /* Prestashop 1.3 */ $ht = round(floatval($product['price']), 4); $ttc = round(floatval($ht + $ht * $tax / 100), 4); /* Set the price for child article (attribute article) */ if (!$isMainProduct) { $ttc += round(floatval($productChildInfos['price']), 4); } } if (GlobalConfig::getDefaultPrice() == 1) { $ProductElem->setAttribute('Tarif_TTC_1', $ttc); } else { $ProductElem->setAttribute('Tarif_TTC_1', 0); $ProductElem->setAttribute('Tarif_TTC_' . GlobalConfig::getDefaultPrice(), $ttc); } $purchasePrice = round(floatval($product['wholesale_price']), 4); /* Set the wholesale price for child article (attribute article) */ if (!$isMainProduct && $productChildInfos['wholesale_price'] != 0) { $purchasePrice = round(floatval($productChildInfos['wholesale_price']), 4); } if ($purchasePrice != 0) { $ProductElem->setAttribute('Prix_Achat', $purchasePrice); } } $weight = $product['weight']; if (!$isMainProduct && $productChildInfos['weight'] != 0) { $weight += $productChildInfos['weight']; } $ProductElem->setAttribute('Poids', $weight); $ean13 = $product['ean13']; if (!$isMainProduct && $productChildInfos['ean13'] != "") { /* If child ean13 not defined, used main product ean13 */ $ean13 = $productChildInfos['ean13']; } if ($ean13 != "") { $ProductElem->setAttribute('Code_Barre', $ean13); } /* Families */ if ($product['families'] != null) { $ProductElem->setAttribute('Famille_1', 'NC'); } /* Init attributes and features */ $attAndFeatures = array("Attribut_1" => "", "Attribut_2" => "", "Attribut_3" => "", "Attribut_4" => "", "Attribut_5" => "", "Attribut_6" => "", "Volume" => "0"); /* Set attributes */ if (is_array($attributesMap)) { foreach ($attributesMap as $attributKey => $attributeName) { $attAndFeatures[$attributKey] = $attributeName; } } /* Set features */ if (is_array($featuresMap)) { foreach ($featuresMap as $key => $value) { $attAndFeatures[$key] = $value; $ProductElem->setAttribute($key, self::convertToUTF8($value)); } } /* Add xml for attributes and features */ $featNumeric = array("Volume"); foreach ($attAndFeatures as $key => $value) { if (in_array($key, $featNumeric)) { if (is_numeric($value)) { $ProductElem->setAttribute($key, $value); } else { $ProductElem->setAttribute($key, 0); } } else { $ProductElem->setAttribute($key, $value); } } /* Add width, height & lenght for Prestashop 1.4 */ if (substr(_PS_VERSION_, 0, 3) > 1.3) { /* Prestashop 1.4 */ $ProductElem->setAttribute('Hauteur', $product['height']); $ProductElem->setAttribute('Largeur', $product['width']); $ProductElem->setAttribute('Longueur', $product['depth']); } /* Hide main product (into OPENSI) when this product has child */ if ($isMainProduct && $product['has_child']) { $ProductElem->setAttribute('Actif', "false"); } else { $ProductElem->setAttribute('Actif', "true"); } $ProductElem->setAttribute('Date_M', Date::dateTimeBdd2DateTimeFr($product['product_date_upd'])); $ProductElem->setAttribute('Date_C', Date::dateTimeBdd2DateTimeFr($product['product_date_add'])); $request->appendChild($ProductElem); $docXml->appendChild($request); return $docXml->saveXML(); }