Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PHP Fatal error: Some transactions have not been committed or rolled back
- try
- {
- Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
- $product = Mage::getModel("catalog/product");
- $productId = $product->getIdBySku("xxxx");
- if(!$productId)
- {
- // new product
- $product->setStoreId(1);
- $product->setWebsiteIds([1]);
- $product->setCreatedAt(strtotime("now"));
- $product->setUpdatedAt(strtotime("now"));
- $product->setTypeId("simple");
- $product->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
- $product->setSku("xxxx");
- $product->setCategoryIds([12]);
- $product->setEan($ean);
- $product->setWeight($weight * 1000);
- }
- else
- {
- // load existing product
- $product = $product->load($productId);
- // reset images
- $mediaApiItems = $mediaApi->items($productId);
- foreach($mediaApiItems as $item)
- {
- $mediaApi->remove($productId, $item["file"]);
- }
- $product->save();
- // load again with new image data
- $product = $product->load($productId);
- }
- $product->setName("title");
- $product->setDescription("desc");
- $product->setShortDescription("desc");
- $product->setIsMassupdate(true);
- $product->setExcludeUrlRewrite(true);
- $product->setName("xxxx");
- $product->setCountryOfManufacture("USA");
- $product->setPrice(0.00);
- $product->setMetaTitle($articleStruct["title"]);
- $product->setMetaDescription("desc");
- // attributes
- $product->setAttributeSetId(10);
- $attr = [
- "manufacterer" => "brand",
- "modell" => "modell",
- "custom_stock_status" => "",
- "hide_default_stock_status" => 1,
- "custom_stock_status_qty_based" => 0,
- "farbe_konf" => 15,
- "delivery_time" => $this->delivery
- ];
- $product->addData($attr);
- $product->setTaxClassId(1);
- $product->setStockData([
- "use_config_manage_stock" => 0,
- "manage_stock" => 1,
- "min_sale_qty" => 1,
- "max_sale_qty" => 1,
- "is_in_stock" => 1,
- "qty" => 1
- ]);
- $product->setStatus(1);
- $product->setMediaGallery(["images"=>[], "values"=>[]]);
- foreach ($articleStruct["images"] as $i => $imageUrl)
- {
- $saveLocation = $imageSaveDir . basename($imageUrl);
- // save image in file system
- if (!file_exists($saveLocation))
- {
- $curl = $this->getCurlClient($imageUrl);
- $data = curl_exec($curl);
- curl_close($curl);
- file_put_contents($saveLocation, $data);
- }
- if ($i == 0)
- $product->addImageToMediaGallery($saveLocation, ["image", "thumbnail", "small_image"], false, false);
- else
- $product->addImageToMediaGallery($saveLocation, [], false, false);
- }
- $product->save();
- }
- catch (Exception $e)
- {
- Mage::log($e->getMessage());
- throw $e;
- }
Add Comment
Please, Sign In to add comment