Пример #1
0
 /**
  * Sets the current product ID.
  * If the product ID is not correct, the current id remains unchanged.
  *
  * @param integer $pid product id
  */
 function setCurrentProductID($pid)
 {
     global $application;
     if ($this->isCorrectProductId($pid)) {
         //                 storefront -          ,                  Offline:
         if (modApiFunc('Users', 'getZone') == "CustomerZone") {
             $prod = new CProductInfo($pid);
             if ($prod->haveOnlineCategory()) {
                 $this->currentProductID = $pid;
             } else {
                 $query = new Request($application->getAppIni('SITE_URL'));
                 $application->redirect($query);
             }
         } else {
             $this->currentProductID = $pid;
         }
     } else {
     }
 }
Пример #2
0
 /**
  * Adds a product into the cart
  *
  * @todo add a user
  * @param array $prod_data product id a set of options
  * @return
  */
 function addToCart($prod_data)
 {
     global $application;
     if (modApiFunc('Catalog', 'isCorrectProductId', $prod_data['entity_id'])) {
         //                 storefront -          ,                  Offline:
         if (modApiFunc('Users', 'getZone') == "CustomerZone") {
             $prod = new CProductInfo($prod_data['entity_id']);
             //         ,                OutOfStock                               .
             $store_show_absent = modApiFunc("Configuration", "getValue", "store_show_absent");
             //             OutOfStock -                       .
             $qty_in_stock = $prod->getProductTagValue('QuantityInStock', PRODUCTINFO_NOT_LOCALIZED_DATA);
             $stock_method = $prod->whichStockControlMethod();
             if ($prod->haveOnlineCategory() && ($stock_method == PRODUCT_OPTIONS_INVENTORY_TRACKING || ($qty_in_stock === "" || $store_show_absent != STORE_SHOW_ABSENT_SHOW_NOT_BUY && $store_show_absent != STORE_SHOW_ABSENT_NOT_SHOW_NOT_BUY || $qty_in_stock > 0))) {
                 if ($prod_data['colorname'] == '') {
                     $cart_id = $prod_data["entity_id"] . "_" . modApiFunc("Product_Options", "getCombinationHash", $prod_data['options']);
                 } else {
                     $cart_id = $prod_data["entity_id"] . "_" . modApiFunc("Product_Options", "getCombinationHash", $prod_data["options"]) . "_" . modApiFunc("ColorSwatch", "getColorHash", $prod_data["colorname"]);
                 }
                 $qty = $prod_data['qty'];
                 $qty = $qty !== NULL && is_numeric($qty) && $qty > 0 ? $qty : 1;
                 if (array_key_exists($cart_id, $this->CartContent)) {
                     $add_to_cart_add_not_replace = modApiFunc('Configuration', 'getValue', SYSCONFIG_STORE_ADD_TO_CART_ADD_NOT_REPLACE);
                     if ($add_to_cart_add_not_replace === true) {
                         $this->CartContent[$cart_id]['quantity'] += $qty;
                     } else {
                         $this->CartContent[$cart_id]['quantity'] = $qty;
                     }
                 } else {
                     //                   ,  . .                           ,                        "               "
                     if (empty($this->CartContent)) {
                         modApiFunc('EventsManager', 'throwEvent', 'CartCreated');
                     }
                     $this->CartContent[$cart_id] = array('product_id' => $prod_data['entity_id'], 'quantity' => $qty, 'options' => $prod_data['options'], 'colorname' => $prod_data['colorname'], 'modifiers' => modApiFunc("Product_Options", "getCombinationModifiers", $prod_data['options']), 'inventory_id' => modApiFunc("Product_Options", "getInventoryIDByCombination", 'product', $prod_data['entity_id'], $prod_data['options']));
                 }
                 modApiFunc('EventsManager', 'throwEvent', 'ProductAddedToCart', $prod_data["entity_id"], $qty);
                 modApiFunc('Session', 'set', 'CartContent', $this->CartContent);
                 $this->buildOrders();
                 return true;
             } else {
                 $query = new Request($application->getAppIni('SITE_URL'));
                 //     :          -           .
                 $application->redirect($query);
             }
         }
     }
     return false;
 }