Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function batchImportAllProductsFromFile($productsToBeInserted){
- foreach ($productsToBeInserted as $key => $customProduct ) {
- $productIDs = $this->getProductIDsByReference($customProduct->MS_CODMAG);
- if (sizeof($productIDs) == 0) {
- $product = new Product();
- } else if (sizeof($productIDs) == 1) {
- $product = new Product($productIDs[0]);
- } else {
- continue;
- }
- $product->reference = $customProduct->MS_CODMAG;
- $product->name = trim($customProduct->MS_DESCRIZIONE);
- $product->price = $customProduct->MS_PREZZO_1;
- $product->out_of_stock = ($customProduct ->MS_ESAURITO === "S" ? true : false);
- $category = null;
- $msGruppoConverted = $this->buildSubGroupCode($customProduct->MS_GRUPPO, $customProduct->MS_SGRUPPO);
- if ($customProduct->MS_GRUPPO !== 0 && $msGruppoConverted !== 0) {
- $product->id_category = [$customProduct->MS_GRUPPO, $msGruppoConverted];
- } else if ($customProduct->MS_GRUPPO === 0 && $msGruppoConverted !== 0) {
- $product->id_category = [$msGruppoConverted];
- } else if ($customProduct ->MS_GRUPPO !== 0 && $msGruppoConverted === 0) {
- $product->id_category = [$customProduct->MS_GRUPPO];
- }
- try {
- if (sizeof($productIDs) == 0) {
- if ($product->add()) {
- $product->updateCategories($product->category);
- $product->addFeatureProductImport($product->id, 1, $customProduct->MS_FAM);
- //StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, Context::getContext()->shop->id);
- }
- } else if (sizeof($productIDs) == 1) {
- if ($product->update()) {
- $product->updateCategories($product->category);
- $alreadySavedFeatures = $product->getFeaturesStatic($productIDs[0]);
- if (sizeof($alreadySavedFeatures) != 1 || $alreadySavedFeatures[0] != $customProduct->MS_FAM) {
- $product->deleteProductFeatures();
- $product->addFeatureProductImport($product->id, 1, $customProduct->MS_FAM);
- }
- }
- }
- } catch (Exception $e) {
- var_dump("Errore: ", $e, $product);
- }
- }
- }
Add Comment
Please, Sign In to add comment