public function createImage($id_stock_image, $name_stock_image) { // First deleting image and linked stock lines if ($id_stock_image != -1) { $this->id_stock_image = trim($id_stock_image); $this->id = $this->id_stock_image; // delete image is Ok, we delete the product lines associated if ($this->delete()) { $id_images = StockImageContent::getImageContentIdsByIdImage($this->id); foreach ($id_images as $id_image) { $image_content = new StockImageContent(); $image_content->id_stock_image_content = $id_image['id_stock_image_content']; $image_content->id = $image_content->id_stock_image_content; $image_content->delete(); } } } // CREATE NEW IMAGE $this->id_stock_image = ''; $this->name = $name_stock_image; $this->type_stock = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'); // Create stock image container if ($this->add(true)) { // For each product in stock, getting necessary informations $products = ErpStock::getAllProductInStock($this->type_stock, (int) Tools::getValue('id_warehouse')); // Saving foreach ($products as $product) { $product['id_stock_image'] = $this->getLastId(); $this->createStockImageContent($product); } } }