Guest User

Untitled

a guest
Oct 16th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. public function batchImportAllProductsFromFile($productsToBeInserted){
  2. foreach ($productsToBeInserted as $key => $customProduct ) {
  3.  
  4. $productIDs = $this->getProductIDsByReference($customProduct->MS_CODMAG);
  5. if (sizeof($productIDs) == 0) {
  6. $product = new Product();
  7. } else if (sizeof($productIDs) == 1) {
  8. $product = new Product($productIDs[0]);
  9. } else {
  10. continue;
  11. }
  12.  
  13. $product->reference = $customProduct->MS_CODMAG;
  14. $product->name = trim($customProduct->MS_DESCRIZIONE);
  15. $product->price = $customProduct->MS_PREZZO_1;
  16. $product->out_of_stock = ($customProduct ->MS_ESAURITO === "S" ? true : false);
  17.  
  18. $category = null;
  19.  
  20. $msGruppoConverted = $this->buildSubGroupCode($customProduct->MS_GRUPPO, $customProduct->MS_SGRUPPO);
  21.  
  22. if ($customProduct->MS_GRUPPO !== 0 && $msGruppoConverted !== 0) {
  23. $product->id_category = [$customProduct->MS_GRUPPO, $msGruppoConverted];
  24. } else if ($customProduct->MS_GRUPPO === 0 && $msGruppoConverted !== 0) {
  25. $product->id_category = [$msGruppoConverted];
  26. } else if ($customProduct ->MS_GRUPPO !== 0 && $msGruppoConverted === 0) {
  27. $product->id_category = [$customProduct->MS_GRUPPO];
  28. }
  29. try {
  30. if (sizeof($productIDs) == 0) {
  31. if ($product->add()) {
  32. $product->updateCategories($product->category);
  33. $product->addFeatureProductImport($product->id, 1, $customProduct->MS_FAM);
  34. //StockAvailable::setQuantity((int)$product->id, 0, $product->quantity, Context::getContext()->shop->id);
  35. }
  36. } else if (sizeof($productIDs) == 1) {
  37. if ($product->update()) {
  38. $product->updateCategories($product->category);
  39. $alreadySavedFeatures = $product->getFeaturesStatic($productIDs[0]);
  40. if (sizeof($alreadySavedFeatures) != 1 || $alreadySavedFeatures[0] != $customProduct->MS_FAM) {
  41. $product->deleteProductFeatures();
  42. $product->addFeatureProductImport($product->id, 1, $customProduct->MS_FAM);
  43. }
  44. }
  45. }
  46. } catch (Exception $e) {
  47. var_dump("Errore: ", $e, $product);
  48. }
  49. }
  50. }
Add Comment
Please, Sign In to add comment