public function delete() { $db = JFactory::getDBO(); $this->clearCache(); $result = true; if (JeproshopShopModelShop::isTableAssociated('product_attribute')) { $shopListIds = JeproshopShopModelShop::getContextListShopIds(); if (count($this->shop_list_id)) { $shopListIds = $this->shop_list_id; } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute_shop') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id . " AND " . $db->quoteName('shop_id') . " IN (" . implode($shopListIds) . ")"; $db->setQuery($query); $result &= $db->query(); } $hasMultiShopEntries = $this->hasMultiShopEntries(); if ($result && !$hasMultiShopEntries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id; $db->setQuery($query); $result &= $db->query(); } if ($this->multi_lang && !$hasMultiShopEntries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_attribute_lang') . " WHERE " . $db->quoteName('product_attribute_id') . " = " . (int) $this->product_attribute_id; $db->setQuery($query); $result &= $db->query(); } if (!$result) { return false; } // Removes the product from StockAvailable, for the current shop JeproshopStockAvailableModelStockAvailable::removeProductFromStockAvailable((int) $this->product_id, (int) $this->product_attribute_id); if ($specific_prices = JeproshopSpecificPriceModelSpecificPrice::getByProductId((int) $this->product_id, (int) $this->product_attribute_id)) { foreach ($specific_prices as $specific_price) { $price = new JeproshopSpecificPriceModelSpecificPrice((int) $specific_price->specific_price_id); $price->delete(); } } if (!$this->hasMultishopEntries() && !$this->deleteAssociations()) { return false; } $this->deleteFromSupplier($this->product_id); JeproshopProductModelProduct::updateDefaultAttribute($this->product_id); return true; }
/** * It is NOT possible to delete a product if there are currently: * - physical stock for this product * - supply order(s) for this product **/ public function delete() { $db = JFactory::getDBO(); if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && $this->advanced_stock_management) { $stockManager = JeproshopStockManagerFactory::getManager(); $physicalQuantity = $stockManager->getProductPhysicalQuantities($this->product_id, 0); $realQuantity = $stockManager->getProductRealQuantities($this->product_id, 0); if ($physicalQuantity > 0) { return false; } if ($realQuantity > $physicalQuantity) { return false; } } $this->clearCache(); $result = true; if (JeproshopShopModelShop::isTableAssociated('product')) { $shopListIds = JeproshopShopModelShop::getContextShopGroupID(); if (count($this->shop_list_id) > 0) { $shopListIds = $this->shop_list_id; } if (!is_array($shopListIds)) { $shopListIds = array($shopListIds); } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_shop') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $this->product_id . " AND " . $db->quoteName('shop_id') . " IN(" . implode($shopListIds) . ")"; $db->setQuery($query); $result &= $db->query(); } $hasMultiShopEntries = $this->hasMultishopEntries(); if ($result && !$hasMultiShopEntries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product') . " WHERE " . $db->quoteName('product_id') . " = " . $this->product_id; $db->setQuery($query); $result &= $db->query(); } if (!$result) { return false; } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_product_lang') . " WHERE " . $db->quoteName('product_id') . " = " . $this->product_id; $db->setQuery($query); $result &= $db->query(); JeproshopStockAvailableModelStockAvailable::removeProductFromStockAvailable($this->product_id); $result &= $this->deleteProductAttributes() && $this->deleteImages() && $this->deleteSceneProducts(); if ($this->hasMultiShopEntries()) { return true; } if (!$result || !JeproshopGroupReductionModelGroupReduction::deleteProductReduction($this->product_id) || !$this->deleteCategories(true) || !$this->deleteProductFeatures() || !$this->deleteTags() || !$this->deleteCartProducts() || !$this->deleteAttributesImpacts() || !$this->deleteAttachments(false) || !$this->deleteCustomization() || !JeproshopSpecificPriceModelSpecificPrice::deleteByProductId((int) $this->product_id) || !$this->deletePack() || !$this->deleteProductSale() || !$this->deleteSearchIndexes() || !$this->deleteAccessories() || !$this->deleteFromAccessories() || !$this->deleteFromSupplier() || !$this->deleteDownload() || !$this->deleteFromCartRules()) { return false; } return true; }