Ejemplo n.º 1
0
 public static function addShopRestriction($shop = NULL, $alias = NULL)
 {
     $context = JeproshopContext::getContext();
     if (!empty($alias)) {
         $alias .= '.';
     }
     /** If there is no shop id, get the context one **/
     if ($shop === null) {
         if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) {
             $shop_group = JeproshopShopModelShop::getContextShopGroup();
         } else {
             $shop_group = $context->shop->getShopGroup();
         }
         $shop = $context->shop;
     } elseif (is_object($shop)) {
         $shop_group = $shop->getShopGroup();
     } else {
         $shop = new JeproshopShopModelShop($shop);
         $shop_group = $shop->getShopGroup();
     }
     /* if quantities are shared between shops of the group */
     $db = JFactory::getDBO();
     if ($shop_group->share_stock) {
         $query = " AND " . $db->escape($alias) . "shop_group_id = " . (int) $shop_group->shop_group_id . " AND " . $db->escape($alias) . "shop_id = 0 ";
     } else {
         $query = " AND " . $db->escape($alias) . "shop_id = " . (int) $shop->shop_id . ' ';
     }
     return $query;
 }
Ejemplo n.º 2
0
 /**
  * For a given {product, product attribute} gets warehouse list
  *
  * @param int $product_id ID of the product
  * @param int $product_attribute_id Optional, uses 0 if this product does not have attributes
  * @param int $shop_id Optional, ID of the shop. Uses the context shop id (@see JeproshopContext::shop)
  * @return array Warehouses (ID, reference/name concatenated)
  */
 public static function getProductWarehouseList($product_id, $product_attribute_id = 0, $shop_id = null)
 {
     $db = JFactory::getDBO();
     // if it's a pack, returns warehouses if and only if some products use the advanced stock management
     if (JeproshopProductPack::isPack($product_id)) {
         $warehouses = JeproshopWarehouseModelWarehouse::getPackWarehouses($product_id);
         /*$res = array();
         		foreach ($warehouses as $warehouse)
         			$res[]['id_warehouse'] = $warehouse; */
         return $warehouses;
     }
     $share_stock = false;
     if ($shop_id === null) {
         if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) {
             $shop_group = JeproshopShopModelShop::getContextShopGroup();
         } else {
             $shop_group = JeproshopContext::getContext()->shop->getShopGroup();
             $shop_id = (int) JeproshopContext::getContext()->shop->shop_id;
         }
         $share_stock = $shop_group->share_stock;
     } else {
         $shop_group = JeproshopShopModelShop::getGroupFromShop($shop_id);
         $share_stock = $shop_group->share_stock;
     }
     if ($share_stock) {
         $shop_ids = JeproshopShopModelShop::getShops(true, (int) $shop_group->shop_group_id, true);
     } else {
         $shop_ids = array((int) $shop_id);
     }
     $query = "SELECT warehouse_product_location.warehouse_id, CONCAT(warehouse.reference, ' - ', warehouse.name)";
     $query .= " AS name FROM " . $db->QuoteName('#__jeproshop_warehouse_product_location') . " AS warehouse_product_location";
     $query .= " INNER JOIN " . $db->quoteName('#__jeproshop_warehouse_shop') . " AS warehouse_shop ON(warehouse_shop.";
     $query .= "warehouse_id = warehouse_product_location.warehouse_id AND shop_id IN (" . implode(',', array_map('intval', $shop_ids));
     $query .= " )) INNER JOIN " . $db->quoteName('#__jeproshop_warehouse') . " AS warehouse ON (warehouse.warehouse_id = warehouse_shop.";
     $query .= "warehouse_id ) WHERE product_id = " . (int) $product_id . " AND product_attribute_id = " . (int) $product_attribute_id;
     $query .= " AND warehouse.deleted = 0 GROUP BY warehouse_product_location.warehouse_id";
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Ejemplo n.º 3
0
 /**
  * Removes a given product from the stock available
  *
  * @param int $product_id
  * @param int $product_attribute_id Optional
  * @param mixed $shop shop id or shop object Optional
  */
 public static function removeProductFromStockAvailable($product_id, $product_attribute_id = null, $shop = null)
 {
     if (!JeproshopTools::isUnsignedInt($product_id)) {
         return false;
     }
     $db = JFactory::getDBO();
     if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
         if (JeproshopShopModelShop::getContextShopGroup()->share_stock == 1) {
             $product_attribute_sql = '';
             if ($product_attribute_id !== null) {
                 $product_attribute_sql = '_attribute';
                 $product_attribute_id_sql = $product_attribute_id;
             } else {
                 $product_attribute_id_sql = $product_id;
             }
             $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product' . $product_attribute_sql . '_shop') . " WHERE " . $db->quoteName('product' . $product_attribute_sql . '_id') . " = ";
             $query .= (int) $product_attribute_id_sql . " AND " . $db->quoteName('shop_id') . " IN (" . implode(',', array_map('intval', JeproshopShopModelShop::getContextListShopIds(JeproshopShopModelShop::SHARE_STOCK))) . ")";
             $db->setQuery($query);
             $result = (int) $db->loadResult();
             if ($result) {
                 return true;
             }
         }
     }
     $query = "DELETE FROM " . $db->quoteName('#__jeproshop_stock_available') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id;
     $query .= ($product_attribute_id ? " AND " . $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id : "") . JeproshopStockAvailableModelStockAvailable::addShopRestriction(null, $shop);
     $db->setQuery($query);
     $res = $db->query();
     if ($product_attribute_id) {
         if ($shop === null || !JeproshopTools::isLoadedObject($shop, 'shop_id')) {
             $shop_datas = new Object();
             JeproshopStockAvailableModelStockAvailable::addSqlShopParams($shop_datas);
             $shop_id = (int) $shop_datas->shop_id;
         } else {
             $shop_id = (int) $shop->shop_id;
         }
         $stock_available = new JeproshopStockAvailableModelStockAvailable();
         $stock_available->product_id = (int) $product_id;
         $stock_available->product_attribute_id = (int) $product_id;
         $stock_available->shop_id = (int) $shop_id;
         $stock_available->postSave();
     }
     JeproshopCache::clean('jeproshop_stock_available_get-quantity_Available_by_product_' . (int) $product_id . '_*');
     return $res;
 }
Ejemplo n.º 4
0
 private function initAttributesForm()
 {
     if (!JeproshopCombinationModelCombination::isFeaturePublished()) {
         $settingPanelLink = '<a href="#" >' . JText::_('COM_JEPROSHOP_PERFORMANCE_LABEL') . '</a>';
         JError::raiseWarning(500, JText::_('COM_JEPROSHOP_FEATURE_HAS_BEEN_DISABLED_MESSAGE') . $settingPanelLink);
     } elseif (JeproshopTools::isLoadedObject($this->product, 'product_id')) {
         if ($this->product_exists_in_shop) {
             if ($this->product->is_virtual) {
                 JError:
                 raiseWarning(500, JText::_('COM_JEPROSHOP_VIRTUAL_PRODUCT_CANNOT_HAVE_COMBINATIONS'));
             } else {
                 $attribute_js = array();
                 $attributes = JeproshopAttributeModelAttribute::getAttributes($this->context->language->lang_id, true);
                 if ($attributes) {
                     foreach ($attributes as $key => $attribute) {
                         $attribute_js[$attribute->attribute_group_id][$attribute->attribute_id] = $attribute->name;
                     }
                 }
                 $this->assignRef('attributeJs', $attribute_js);
                 $attributes_groups = JeproshopAttributeGroupModelAttributeGroup::getAttributesGroups($this->context->language->lang_id);
                 $this->assignRef('attributes_groups', $attributes_groups);
                 $images = JeproshopImageModelImage::getImages($this->context->language->lang_id, $this->product->product_id);
                 $weight_unit = JeproshopSettingModelSetting::getValue('weight_unit');
                 $this->assignRef('weight_unit', $weight_unit);
                 $reasons = JeproshopStockMovementReasonModelStockMovementReason::getStockMovementReasons();
                 $this->assignRef('reasons', $reasons);
                 //$this->assignRef('minimal_quantity', );
                 $this->assignRef('available_date', $available_date);
                 $stock_mvt_default_reason = JeproshopSettingModelSetting::getValue('default_stock_mvt_reason');
                 $this->assignRef('default_stock_mvt_reason', $stock_mvt_default_reason);
                 $i = 0;
                 /*$type = JeproshopImageTypeModelImageType::getByNameNType('%', 'products', 'height');
                   if (isset($type->name)){
                       $data->assign('imageType', $type['name']);
                   }else
                       $data->assign('imageType', 'small_default'); */
                 //$this->assignRef('imageWidth', (isset($image_type->width) ? (int)($image_type->width) : 64) + 25);
                 foreach ($images as $k => $image) {
                     $images[$k]->obj = new JeproshopImageModelImage($image->image_id);
                     ++$i;
                 }
                 $this->assignRef('attribute_images', $images);
                 $attributeList = $this->renderAttributesList($this->product, $this->currency);
                 $this->assignRef('list', $attributeList);
                 $combination_exists = JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getContextShopGroup()->share_stock && count(JeproshopAttributeGroupModelAttributeGroup::getAttributesGroups($this->context->language->lang_id)) > 0 && $this->product->hasAttributes();
                 $this->assignRef('combination_exists', $combination_exists);
             }
         }
     }
 }