Guest User

Untitled

a guest
Sep 26th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. PHP Fatal error: Some transactions have not been committed or rolled back
  2.  
  3. try
  4. {
  5. Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
  6. $product = Mage::getModel("catalog/product");
  7. $productId = $product->getIdBySku("xxxx");
  8. if(!$productId)
  9. {
  10. // new product
  11. $product->setStoreId(1);
  12. $product->setWebsiteIds([1]);
  13. $product->setCreatedAt(strtotime("now"));
  14. $product->setUpdatedAt(strtotime("now"));
  15. $product->setTypeId("simple");
  16. $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
  17. $product->setSku("xxxx");
  18. $product->setCategoryIds([12]);
  19. $product->setEan($ean);
  20. $product->setWeight($weight * 1000);
  21. }
  22. else
  23. {
  24. // load existing product
  25. $product = $product->load($productId);
  26.  
  27. // reset images
  28. $mediaApiItems = $mediaApi->items($productId);
  29. foreach($mediaApiItems as $item)
  30. {
  31. $mediaApi->remove($productId, $item["file"]);
  32. }
  33. $product->save();
  34.  
  35. // load again with new image data
  36. $product = $product->load($productId);
  37. }
  38.  
  39.  
  40. $product->setName("title");
  41. $product->setDescription("desc");
  42. $product->setShortDescription("desc");
  43. $product->setIsMassupdate(true);
  44. $product->setExcludeUrlRewrite(true);
  45. $product->setName("xxxx");
  46. $product->setCountryOfManufacture("USA");
  47. $product->setPrice(0.00);
  48. $product->setMetaTitle($articleStruct["title"]);
  49. $product->setMetaDescription("desc");
  50.  
  51. // attributes
  52. $product->setAttributeSetId(10);
  53. $attr = [
  54. "manufacterer" => "brand",
  55. "modell" => "modell",
  56. "custom_stock_status" => "",
  57. "hide_default_stock_status" => 1,
  58. "custom_stock_status_qty_based" => 0,
  59. "farbe_konf" => 15,
  60. "delivery_time" => $this->delivery
  61. ];
  62. $product->addData($attr);
  63. $product->setTaxClassId(1);
  64.  
  65. $product->setStockData([
  66. "use_config_manage_stock" => 0,
  67. "manage_stock" => 1,
  68. "min_sale_qty" => 1,
  69. "max_sale_qty" => 1,
  70. "is_in_stock" => 1,
  71. "qty" => 1
  72. ]);
  73. $product->setStatus(1);
  74.  
  75. $product->setMediaGallery(["images"=>[], "values"=>[]]);
  76. foreach ($articleStruct["images"] as $i => $imageUrl)
  77. {
  78. $saveLocation = $imageSaveDir . basename($imageUrl);
  79.  
  80. // save image in file system
  81. if (!file_exists($saveLocation))
  82. {
  83. $curl = $this->getCurlClient($imageUrl);
  84. $data = curl_exec($curl);
  85. curl_close($curl);
  86.  
  87. file_put_contents($saveLocation, $data);
  88. }
  89.  
  90. if ($i == 0)
  91. $product->addImageToMediaGallery($saveLocation, ["image", "thumbnail", "small_image"], false, false);
  92. else
  93. $product->addImageToMediaGallery($saveLocation, [], false, false);
  94. }
  95.  
  96. $product->save();
  97. }
  98. catch (Exception $e)
  99. {
  100. Mage::log($e->getMessage());
  101. throw $e;
  102. }
Add Comment
Please, Sign In to add comment