public static function setProductReduction($id_product, $id_group = null, $id_category = null, $reduction = null) { $res = true; GroupReduction::deleteProductReduction((int) $id_product); $categories = Product::getProductCategories((int) $id_product); if ($categories) { foreach ($categories as $category) { $reductions = GroupReduction::getGroupsByCategoryId((int) $category); if ($reductions) { foreach ($reductions as $reduction) { $current_group_reduction = new GroupReduction((int) $reduction['id_group_reduction']); $res &= $current_group_reduction->_setCache(); } } } } return $res; }
public static function setProductReduction($id_product, $id_group = null, $id_category, $reduction = null) { $res = true; GroupReduction::deleteProductReduction((int) $id_product); $reductions = GroupReduction::getGroupsByCategoryId((int) $id_category); if ($reductions) { foreach ($reductions as $reduction) { $res &= Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'product_group_reduction_cache` (`id_product`, `id_group`, `reduction`) VALUES (' . (int) $id_product . ', ' . (int) $reduction['id_group'] . ', ' . (double) $reduction['reduction'] . ')'); } } return $res; }
/** * Set Group reduction if needed */ public function setGroupReduction() { $row = GroupReduction::getGroupByCategoryId((int) $this->id_category_default); if (!$row) { if (!GroupReduction::deleteProductReduction((int) $this->id)) { return false; } } else { if (!GroupReduction::setProductReduction((int) $this->id, $row['id_group'], (int) $this->id_category_default, (double) $row['reduction'])) { return false; } } return true; }
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 = Adapter_ServiceLocator::get('Core_Foundation_Database_EntityManager')->getRepository('WarehouseProductLocation')->findByIdProduct($this->id); foreach ($warehouse_product_locations as $warehouse_product_location) { $warehouse_product_location->delete(); } $stocks = Adapter_ServiceLocator::get('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() && $this->deleteSceneProducts(); // 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; }