Exemplo n.º 1
0
 public static function setProductReduction($product_id, $group_id = null, $category_id, $reduction = null)
 {
     $res = true;
     JeproshopGroupReductionModelGroupReduction::deleteProductReduction((int) $product_id);
     $reductions = JeproshopGroupReductionModelGroupReduction::getGroupsByCategoryId((int) $category_id);
     if ($reductions) {
         $db = JFactory::getDBO();
         foreach ($reductions as $reduction) {
             $query = "INSERT INTO " . $db->quoteName('#__jeproshop_product_group_reduction_cache') . " (" . $db->quoteName('product_id');
             $query .= ", " . $db->quoteName('group_id') . ", " . $db->quoteName('reduction') . ") VALUES (" . (int) $product_id . ", ";
             $query .= (int) $reduction->group_id . ", " . (double) $reduction->reduction . ")";
             $db->setQuery($query);
             $res &= $db->query();
         }
     }
     return $res;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }