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 id, sets if product is available out of stocks
  *
  * @param int $product_id
  * @param bool $out_of_stock Optional false by default
  * @param int $shop_id Optional gets context by default
  * @param int $product_attribute_id
  * @return bool
  */
 public static function setProductOutOfStock($product_id, $out_of_stock = false, $shop_id = null, $product_attribute_id = 0)
 {
     if (!JeproshopTools::isUnsignedInt($product_id)) {
         return false;
     }
     $db = JFactory::getDBO();
     $existing_id = JeproshopStockAvailableModelStockAvailable::getStockAvailableIdByProductId((int) $product_id, (int) $product_attribute_id, $shop_id);
     if ($existing_id > 0) {
         $query = "UPDATE " . $db->quoteName('#__jeproshop_stock_available') . " SET " . $db->quoteName('out_of_stock') . " = " . (int) $out_of_stock;
         $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . ($product_attribute_id ? " AND " . $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id : " ");
         $query .= JeproshopStockAvailableModelStockAvailable::addShopRestriction($shop_id);
         $db->setQuery($query);
         $db->query();
     } else {
         $context = JeproshopContext::getContext();
         $groupOk = false;
         // get shop group too
         if ($shop_id === null) {
             if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) {
                 $shop_group = JeproshopShopModelShop::getContextShopGroupID();
             } else {
                 $shop_group = $context->shop->getShopGroup();
                 $shop_id = $context->shop->shop_id;
             }
         } else {
             $shop = new JeproshopShopModelShop($shop_id);
             $shop_group = $shop->getShopGroup();
         }
         // if quantities are shared between shops of the group
         if ($shop_group->share_stock) {
             $fields = ", " . $db->quoteName('shop_group_id') . ", " . $db->quoteName('shop_d');
             $values = ", " . (int) $shop_group->shop_group_id . ", 0";
             $groupOk = true;
         } else {
             $fields = ", " . $db->quoteName('shop_group_id');
             $values = ", 0";
         }
         // if no group specific restriction, set simple shop restriction
         if (!$groupOk) {
             $fields = ", " . $db->quoteName('shop_id');
             $values = ", " . (int) $shop_id;
         }
         $query = "INSERT INTO " . $db->quoteName('#__jeproshop_stock_available') . "(" . $db->quoteName('out_of_stock') . ", " . $db->quoteName('product_id');
         $query .= ", " . $db->quoteName('product_attribute_id') . $fields . ") VALUES (" . (int) $out_of_stock . ", " . (int) $product_id . ", " . $product_attribute_id . $values . ")";
         $db->setQuery($query);
         $db->query();
     }
 }