/** * * This method allow to add stock information on a product detail * * If advanced stock management is active, get physical stock of this product in the warehouse associated to the product for the current order * Else get the available quantity of the product in function of the shop associated to the order * * @param array &$product */ protected function setProductCurrentStock(&$product) { if (JeproshopSettingModelSetting::getValue('advanced_stock_management') && (int) $product->advanced_stock_management == 1 && (int) $product->warehouse_id > 0) { $product->current_stock = JeproshopStockManagerFactory::getManager()->getProductPhysicalQuantities($product->product_id, $product->product_attribute_id, (int) $product->warehouse_id, true); } else { $product->current_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, $product->product_attribute_id, (int) $this->shop_id); } }
public function delete() { $app = JFactory::getApplication(); $product_id = $app->input->get('product_id'); $product = new JeproshopProductModelProduct((int) $product_id); if (JeproshopTools::isLoadedObject($product, 'product_id') && isset($this->fieldImageSettings)) { // check if request at least one object with noZeroObject if (isset($product->noZeroObject) && count($taxes = call_user_func(array('JeproshopProductModelProduct', $product->noZeroObject))) <= 1) { $this->has_errors = true; JError::raiseError(500, JText::_('COM_JEPROSHOP_YOU_NEED_AT_LEAST_ONE_LABEL') . ' <b> ' . JText::_('COM_JEPROSHOP_PRODUCT_LABEL') . ' </b><br />' . JText::_('COM_JEPROSHOP_YOU_CANNOT_DELETE_ALL_OF_THE_ITEMS_LABEL')); } else { /* * @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 (JeproshopSettingModelSetting::getValue('advanced_stock_management') && $product->advanced_stock_management) { $stock_manager = JeproshopStockManagerFactory::getManager(); $physical_quantity = $stock_manager->getProductPhysicalQuantities($product->product_id, 0); $real_quantity = $stock_manager->getProductRealQuantities($product->product_id, 0); if ($physical_quantity > 0 || $real_quantity > $physical_quantity) { $this->has_errors = true; JError::raiseError('COM_JEPROSHOP_YOU_CANNOT_DELETE_THIS_BECAUSE_THERE_IS_PHYSICAL_STOCK_LEFT_LABEL'); } } if (!$this->has_errors) { if ($product->delete()) { $category_id = (int) $app->input->get('category_id'); $category_url = empty($category_id) ? '' : '&category_id=' . (int) $category_id; $app->enqueueMessage(JText::_('COM_JEPROSHOP_PRODUCT_LABEL') . ' ' . $product->product_id . ' ' . JText::_('COM_JEPROSHOP_WAS_SUCCESSFULLY_DELETED_BY_MESSAGE') . ' ' . JeproshopContext::getContext()->employee->firstname . ' ' . JeproshopContext::getContext()->employee->lastname); $redirect_after = 'index.php?option=com_jeproshop&view=product&conf=1&' . JeproshopTools::getProductToken() . '=1' . $category_url; $app->redirect($redirect_after); } else { $this->has_errors = true; Tools::displayError('An error occurred during deletion.'); } } } } else { $this->has_errors = true; JError::raiseError(500, JText::_('COM_JEPROSHOP_AN_ERROR_OCCURRED_WHILE_DELETING_THE_PRODUCT_MESSAGE') . ' <b> ' . JText::_('COM_JEPROSHOP_PRODUCT_LABEL') . '</b> ' . JText::_('COM_JEPROSHOP_CANNOT_BE_LOADED_MESSAGE')); } }
/** * Returns a StockManager * * @return StockManagerInterface */ public static function getManager() { if (!isset(JeproshopStockManagerFactory::$stock_manager)) { $stock_manager = JeproshopStockManagerFactory::execHookStockManagerFactory(); if (!$stock_manager instanceof StockManagerInterface) { $stock_manager = new JeproshopStockManager(); } JeproshopStockManagerFactory::$stock_manager = $stock_manager; } return JeproshopStockManagerFactory::$stock_manager; }
/** * 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; }