} else {
     $action = strtoupper($_REQUEST[$arParams["ACTION_VARIABLE"]]);
 }
 $productID = intval($_REQUEST[$arParams["PRODUCT_ID_VARIABLE"]]);
 if (($action == "ADD2BASKET" || $action == "BUY" || $action == "SUBSCRIBE_PRODUCT") && $productID > 0) {
     if (CModule::IncludeModule("sale") && CModule::IncludeModule("catalog")) {
         if ($arParams["USE_PRODUCT_QUANTITY"]) {
             $QUANTITY = intval($_POST[$arParams["PRODUCT_QUANTITY_VARIABLE"]]);
         }
         if ($QUANTITY <= 1) {
             $QUANTITY = 1;
         }
         $product_properties = array();
         if (count($arParams["PRODUCT_PROPERTIES"])) {
             if (is_array($_POST[$arParams["PRODUCT_PROPS_VARIABLE"]])) {
                 $product_properties = CIBlockPriceTools::CheckProductProperties($arParams["IBLOCK_ID"], $productID, $arParams["PRODUCT_PROPERTIES"], $_POST[$arParams["PRODUCT_PROPS_VARIABLE"]]);
                 if (!is_array($product_properties)) {
                     $strError = GetMessage("CATALOG_ERROR2BASKET") . ".";
                 }
             } else {
                 $strError = GetMessage("CATALOG_ERROR2BASKET") . ".";
             }
         }
         if (is_array($arParams["OFFERS_CART_PROPERTIES"])) {
             foreach ($arParams["OFFERS_CART_PROPERTIES"] as $i => $pid) {
                 if ($pid === "") {
                     unset($arParams["OFFERS_CART_PROPERTIES"][$i]);
                 }
             }
             if (!empty($arParams["OFFERS_CART_PROPERTIES"])) {
                 $product_properties = CIBlockPriceTools::GetOfferProperties($productID, $arParams["IBLOCK_ID"], $arParams["OFFERS_CART_PROPERTIES"]);
Exemple #2
0
 } else {
     $action = strtoupper($_REQUEST[$arParams["ACTION_VARIABLE"]]);
 }
 $productID = (int) $_REQUEST[$arParams["PRODUCT_ID_VARIABLE"]];
 if (($action == "ADD2BASKET" || $action == "BUY" || $action == "SUBSCRIBE_PRODUCT") && $productID > 0) {
     if (Loader::includeModule("sale") && Loader::includeModule("catalog")) {
         $addByAjax = isset($_REQUEST['ajax_basket']) && 'Y' == $_REQUEST['ajax_basket'];
         $QUANTITY = 0;
         $product_properties = array();
         $intProductIBlockID = (int) CIBlockElement::GetIBlockByID($productID);
         if (0 < $intProductIBlockID) {
             if ($arParams['ADD_PROPERTIES_TO_BASKET'] == 'Y') {
                 if ($intProductIBlockID == $arParams["IBLOCK_ID"]) {
                     if (!empty($arParams["PRODUCT_PROPERTIES"])) {
                         if (isset($_REQUEST[$arParams["PRODUCT_PROPS_VARIABLE"]]) && is_array($_REQUEST[$arParams["PRODUCT_PROPS_VARIABLE"]])) {
                             $product_properties = CIBlockPriceTools::CheckProductProperties($arParams["IBLOCK_ID"], $productID, $arParams["PRODUCT_PROPERTIES"], $_REQUEST[$arParams["PRODUCT_PROPS_VARIABLE"]], $arParams['PARTIAL_PRODUCT_PROPERTIES'] == 'Y');
                             if (!is_array($product_properties)) {
                                 $strError = GetMessage("CATALOG_PARTIAL_BASKET_PROPERTIES_ERROR");
                                 $successfulAdd = false;
                             }
                         } else {
                             $strError = GetMessage("CATALOG_EMPTY_BASKET_PROPERTIES_ERROR");
                             $successfulAdd = false;
                         }
                     }
                 } else {
                     $skuAddProps = isset($_REQUEST['basket_props']) && !empty($_REQUEST['basket_props']) ? $_REQUEST['basket_props'] : '';
                     if (!empty($arParams["OFFERS_CART_PROPERTIES"]) || !empty($skuAddProps)) {
                         $product_properties = CIBlockPriceTools::GetOfferProperties($productID, $arParams["IBLOCK_ID"], $arParams["OFFERS_CART_PROPERTIES"], $skuAddProps);
                     }
                 }
Exemple #3
0
 /**
  * Process Puy Product.
  *
  * @param int $productID
  * @param float $quantity
  * @param array $values
  * @param array $arRewriteFields
  * @throws void|Bitrix\Main\SystemException
  */
 protected function addProductToBasket($productID, $quantity, $values = array(), $arRewriteFields = array())
 {
     $productProperties = array();
     $productID = (int) $productID;
     $intProductIBlockID = (int) CIBlockElement::GetIBlockByID($productID);
     if ($intProductIBlockID > 0) {
         $productCatalogInfo = CCatalogSKU::getInfoByIblock($intProductIBlockID);
         $isOffer = CCatalogSKU::TYPE_OFFERS == $productCatalogInfo['CATALOG_TYPE'];
         if ($this->arParams['ADD_PROPERTIES_TO_BASKET'] == 'Y') {
             // Is not offer
             if (!$isOffer) {
                 // Props not empty
                 if (!empty($this->arParams['CART_PROPERTIES'][$intProductIBlockID])) {
                     $productProperties = CIBlockPriceTools::CheckProductProperties($intProductIBlockID, $productID, $this->arParams['CART_PROPERTIES'][$intProductIBlockID], $values, $this->arParams['PARTIAL_PRODUCT_PROPERTIES'] == 'Y');
                     if (!is_array($productProperties)) {
                         throw new SystemException(Loc::getMessage("CVP_PARTIAL_BASKET_PROPERTIES_ERROR"));
                     }
                 }
             } else {
                 if (!empty($this->arParams['CART_PROPERTIES'][$intProductIBlockID])) {
                     $productProperties = CIBlockPriceTools::GetOfferProperties($productID, $productCatalogInfo['PRODUCT_IBLOCK_ID'], $this->arParams['CART_PROPERTIES'][$intProductIBlockID]);
                 }
             }
         }
         if (0 >= $quantity) {
             $rsRatios = CCatalogMeasureRatio::getList(array(), array('PRODUCT_ID' => $productID), false, false, array('PRODUCT_ID', 'RATIO'));
             if ($arRatio = $rsRatios->Fetch()) {
                 $intRatio = (int) $arRatio['RATIO'];
                 $dblRatio = (double) $arRatio['RATIO'];
                 $quantity = $dblRatio > $intRatio ? $dblRatio : $intRatio;
             }
         }
         if (0 >= $quantity) {
             $quantity = 1;
         }
     } else {
         throw new SystemException(Loc::getMessage('CVP_CATALOG_PRODUCT_NOT_FOUND') . ".");
     }
     if (!Add2BasketByProductID($productID, $quantity, $arRewriteFields, $productProperties)) {
         throw new SystemException(Loc::getMessage("CVP_CATALOG_ERROR2BASKET") . ".");
     }
 }