예제 #1
0
 public function delete()
 {
     if (!parent::delete()) {
         return false;
     }
     // Removes the product from StockAvailable, for the current shop
     StockAvailable::removeProductFromStockAvailable((int) $this->id_product, (int) $this->id);
     if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) {
         return false;
     }
     return true;
 }
예제 #2
0
 public function delete()
 {
     if (!parent::delete()) {
         return false;
     }
     // Removes the product from StockAvailable, for the current shop
     StockAvailable::removeProductFromStockAvailable((int) $this->id_product, (int) $this->id);
     if ($specific_prices = SpecificPrice::getByProductId((int) $this->id_product, (int) $this->id)) {
         foreach ($specific_prices as $specific_price) {
             $price = new SpecificPrice((int) $specific_price['id_specific_price']);
             $price->delete();
         }
     }
     if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) {
         return false;
     }
     return true;
 }
예제 #3
0
 public function delete()
 {
     if (!parent::delete()) {
         return false;
     }
     // Removes the product from StockAvailable, for the current shop
     StockAvailable::removeProductFromStockAvailable((int) $this->id_product, (int) $this->id);
     if ($specific_prices = SpecificPrice::getByProductId((int) $this->id_product, (int) $this->id)) {
         foreach ($specific_prices as $specific_price) {
             $price = new SpecificPrice((int) $specific_price['id_specific_price']);
             $price->delete();
         }
     }
     if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) {
         return false;
     }
     $this->deleteFromSupplier($this->id_product);
     Product::updateDefaultAttribute($this->id_product);
     Tools::clearColorListCache((int) $this->id_product);
     return true;
 }
 public function processGenerate()
 {
     if (!is_array(Tools::getValue('options'))) {
         $this->errors[] = Tools::displayError('Please select at least one attribute.');
     } else {
         $tab = array_values(Tools::getValue('options'));
         if (count($tab) && Validate::isLoadedObject($this->product)) {
             AdminAttributeGeneratorController::setAttributesImpacts($this->product->id, $tab);
             $this->combinations = array_values(AdminAttributeGeneratorController::createCombinations($tab));
             $values = array_values(array_map(array($this, 'addAttribute'), $this->combinations));
             // @since 1.5.0
             if ($this->product->depends_on_stock == 0) {
                 $attributes = Product::getProductAttributesIds($this->product->id, true);
                 foreach ($attributes as $attribute) {
                     StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], Context::getContext()->shop);
                 }
             }
             SpecificPriceRule::disableAnyApplication();
             $this->product->deleteProductAttributes();
             $this->product->generateMultipleCombinations($values, $this->combinations);
             // @since 1.5.0
             if ($this->product->depends_on_stock == 0) {
                 $attributes = Product::getProductAttributesIds($this->product->id, true);
                 $quantity = str_replace(',', '.', Tools::getValue('quantity'));
                 foreach ($attributes as $attribute) {
                     StockAvailable::setQuantity($this->product->id, $attribute['id_product_attribute'], $quantity);
                 }
             } else {
                 StockAvailable::synchronize($this->product->id);
             }
             SpecificPriceRule::enableAnyApplication();
             SpecificPriceRule::applyAllRules(array((int) $this->product->id));
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts') . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&key_tab=Combinations&conf=4');
         } else {
             $this->errors[] = Tools::displayError('Unable to initialize these parameters. A combination is missing or an object cannot be loaded.');
         }
     }
 }
 public function processGenerate()
 {
     if (!is_array(Tools::getValue('options'))) {
         $this->errors[] = $this->trans('Please select at least one attribute.', array(), 'Admin.Catalog.Notification');
     } else {
         $tab = array_values(Tools::getValue('options'));
         if (count($tab) && Validate::isLoadedObject($this->product)) {
             AdminAttributeGeneratorController::setAttributesImpacts($this->product->id, $tab);
             $this->combinations = array_values(AdminAttributeGeneratorController::createCombinations($tab));
             $values = array_values(array_map(array($this, 'addAttribute'), $this->combinations));
             // @since 1.5.0
             if ($this->product->depends_on_stock == 0) {
                 $attributes = Product::getProductAttributesIds($this->product->id, true);
                 foreach ($attributes as $attribute) {
                     StockAvailable::removeProductFromStockAvailable($this->product->id, $attribute['id_product_attribute'], Context::getContext()->shop);
                 }
             }
             SpecificPriceRule::disableAnyApplication();
             $this->product->deleteProductAttributes();
             $this->product->generateMultipleCombinations($values, $this->combinations);
             // Reset cached default attribute for the product and get a new one
             Product::getDefaultAttribute($this->product->id, 0, true);
             Product::updateDefaultAttribute($this->product->id);
             // @since 1.5.0
             if ($this->product->depends_on_stock == 0) {
                 $attributes = Product::getProductAttributesIds($this->product->id, true);
                 $quantity = (int) Tools::getValue('quantity');
                 foreach ($attributes as $attribute) {
                     if (Shop::getContext() == Shop::CONTEXT_ALL) {
                         $shops_list = Shop::getShops();
                         if (is_array($shops_list)) {
                             foreach ($shops_list as $current_shop) {
                                 if (isset($current_shop['id_shop']) && (int) $current_shop['id_shop'] > 0) {
                                     StockAvailable::setQuantity($this->product->id, (int) $attribute['id_product_attribute'], $quantity, (int) $current_shop['id_shop']);
                                 }
                             }
                         }
                     } else {
                         StockAvailable::setQuantity($this->product->id, (int) $attribute['id_product_attribute'], $quantity);
                     }
                 }
             } else {
                 StockAvailable::synchronize($this->product->id);
             }
             SpecificPriceRule::enableAnyApplication();
             SpecificPriceRule::applyAllRules(array((int) $this->product->id));
             Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts') . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&key_tab=Combinations&conf=4');
         } else {
             $this->errors[] = $this->trans('Unable to initialize these parameters. A combination is missing or an object cannot be loaded.');
         }
     }
 }
예제 #6
0
 public function delete()
 {
     /*
      * @since 1.5.0
      * It is NOT possible to delete a product if there are currently:
      * - physical stock for this product
      * - supply order(s) for this product
      */
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $this->advanced_stock_management) {
         $stock_manager = StockManagerFactory::getManager();
         $physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
         $real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
         if ($physical_quantity > 0) {
             return false;
         }
         if ($real_quantity > $physical_quantity) {
             return false;
         }
     }
     // Removes the product from StockAvailable, for the current shop
     StockAvailable::removeProductFromStockAvailable($this->id);
     $result = parent::delete();
     $result &= $this->deleteProductAttributes() && $this->deleteImages() && $this->deleteSceneProducts();
     // If there are still entries in product_shop, don't remove completly the product
     if ($this->hasMultishopEntries()) {
         return true;
     }
     Hook::exec('actionProductDelete', array('product' => $this));
     if (!$result || !GroupReduction::deleteProductReduction($this->id) || !$this->deleteCategories(true) || !$this->deleteProductFeatures() || !$this->deleteTags() || !$this->deleteCartProducts() || !$this->deleteAttributesImpacts() || !$this->deleteAttachments() || !$this->deleteCustomization() || !SpecificPrice::deleteByProductId((int) $this->id) || !$this->deletePack() || !$this->deleteProductSale() || !$this->deleteSearchIndexes() || !$this->deleteAccessories() || !$this->deleteFromAccessories() || !$this->deleteFromSupplier() || !$this->deleteDownload() || !$this->deleteFromCartRules()) {
         return false;
     }
     return true;
 }
예제 #7
0
파일: Product.php 프로젝트: M03G/PrestaShop
 public function delete()
 {
     /*
      * @since 1.5.0
      * It is NOT possible to delete a product if there are currently:
      * - physical stock for this product
      * - supply order(s) for this product
      */
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $this->advanced_stock_management) {
         $stock_manager = StockManagerFactory::getManager();
         $physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
         $real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
         if ($physical_quantity > 0) {
             return false;
         }
         if ($real_quantity > $physical_quantity) {
             return false;
         }
         $warehouse_product_locations = \PrestaShop\PrestaShop\Adapter\ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Foundation\\Database\\EntityManager')->getRepository('WarehouseProductLocation')->findByIdProduct($this->id);
         foreach ($warehouse_product_locations as $warehouse_product_location) {
             $warehouse_product_location->delete();
         }
         $stocks = \PrestaShop\PrestaShop\Adapter\ServiceLocator::get('\\PrestaShop\\PrestaShop\\Core\\Foundation\\Database\\EntityManager')->getRepository('Stock')->findByIdProduct($this->id);
         foreach ($stocks as $stock) {
             $stock->delete();
         }
     }
     $result = parent::delete();
     // Removes the product from StockAvailable, for the current shop
     StockAvailable::removeProductFromStockAvailable($this->id);
     $result &= $this->deleteProductAttributes() && $this->deleteImages();
     // If there are still entries in product_shop, don't remove completely the product
     if ($this->hasMultishopEntries()) {
         return true;
     }
     Hook::exec('actionProductDelete', array('id_product' => (int) $this->id, 'product' => $this));
     if (!$result || !GroupReduction::deleteProductReduction($this->id) || !$this->deleteCategories(true) || !$this->deleteProductFeatures() || !$this->deleteTags() || !$this->deleteCartProducts() || !$this->deleteAttributesImpacts() || !$this->deleteAttachments(false) || !$this->deleteCustomization() || !SpecificPrice::deleteByProductId((int) $this->id) || !$this->deletePack() || !$this->deleteProductSale() || !$this->deleteSearchIndexes() || !$this->deleteAccessories() || !$this->deleteFromAccessories() || !$this->deleteFromSupplier() || !$this->deleteDownload() || !$this->deleteFromCartRules()) {
         return false;
     }
     return true;
 }