Exemple #1
0
 public function getBasketItems()
 {
     global $APPLICATION;
     if (self::$catalogIncluded === null) {
         self::$catalogIncluded = Loader::includeModule('catalog');
     }
     self::$iblockIncluded = self::$catalogIncluded;
     CSaleBasket::UpdateBasketPrices(CSaleBasket::GetBasketUserID(), SITE_ID);
     $bShowReady = false;
     $bShowDelay = false;
     $bShowSubscribe = false;
     $bShowNotAvail = false;
     $allSum = 0;
     $allWeight = 0;
     $allCurrency = CSaleLang::GetLangCurrency(SITE_ID);
     $allVATSum = 0;
     $arParents = array();
     $arResult["ITEMS"]["AnDelCanBuy"] = array();
     $arResult["ITEMS"]["DelDelCanBuy"] = array();
     $arResult["ITEMS"]["nAnCanBuy"] = array();
     $arResult["ITEMS"]["ProdSubscribe"] = array();
     $DISCOUNT_PRICE_ALL = 0;
     // BASKET PRODUCTS (including measures, ratio, iblock properties data)
     $arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE");
     $arBasketItems = array();
     $basketKey = 0;
     $basketIds = array();
     $arSku2Parent = array();
     $arSetParentWeight = array();
     $arElementId = array();
     $dbItems = CSaleBasket::GetList(array("ID" => "ASC"), array("FUSER_ID" => CSaleBasket::GetBasketUserID(), "LID" => SITE_ID, "ORDER_ID" => "NULL"), false, false, array("ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID", "PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID"));
     while ($arItem = $dbItems->GetNext()) {
         $arItem['PROPS'] = array();
         $arBasketItems[$basketKey] = $arItem;
         $basketIds[$arItem['ID']] =& $arBasketItems[$basketKey];
         $basketKey++;
         if (CSaleBasketHelper::isSetItem($arItem)) {
             continue;
         }
         $arElementId[] = $arItem["PRODUCT_ID"];
     }
     if (!empty($arElementId) && self::$catalogIncluded) {
         $productList = CCatalogSKU::getProductList($arElementId);
         if (!empty($productList)) {
             foreach ($productList as $offerId => $offerInfo) {
                 $offerInfo['PRODUCT_ID'] = $offerInfo['ID'];
                 $arElementId[] = $offerInfo['ID'];
                 $arSku2Parent[$offerId] = $offerInfo['ID'];
                 $arParents[$offerId] = $offerInfo;
             }
             unset($offerInfo, $offerId);
         }
         unset($productList);
         // get measures, ratio, sku props data and available quantity
         $arBasketItems = getMeasures($arBasketItems);
         $arBasketItems = getRatio($arBasketItems);
         $arBasketItems = $this->getAvailableQuantity($arBasketItems);
         $propsIterator = CSaleBasket::GetPropsList(array('BASKET_ID' => 'ASC', 'SORT' => 'ASC', 'ID' => 'ASC'), array('BASKET_ID' => array_keys($basketIds)));
         while ($property = $propsIterator->GetNext()) {
             $property['CODE'] = (string) $property['CODE'];
             if ($property['CODE'] == 'CATALOG.XML_ID' || $property['CODE'] == 'PRODUCT.XML_ID') {
                 continue;
             }
             if (!isset($basketIds[$property['BASKET_ID']])) {
                 continue;
             }
             $basketIds[$property['BASKET_ID']]['PROPS'][] = $property;
         }
         unset($property, $propsIterator, $basketIds);
     }
     // get product properties data
     $arProductData = getProductProps($arElementId, array_merge(array("ID"), $arImgFields, $this->arCustomSelectFields));
     foreach ($arBasketItems as &$arItem) {
         $quantityIsFloat = false;
         if (number_format(doubleval($arItem['QUANTITY']), 2, '.', '') != intval($arItem['QUANTITY'])) {
             $quantityIsFloat = true;
         }
         $arItem["QUANTITY"] = $quantityIsFloat === false && $this->quantityFloat != "Y" ? intval($arItem['QUANTITY']) : number_format(doubleval($arItem['QUANTITY']), 2, '.', '');
         $arItem["PRICE_VAT_VALUE"] = $arItem["PRICE"] / ($arItem["VAT_RATE"] + 1) * $arItem["VAT_RATE"];
         $arItem["PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arItem["PRICE"], $arItem["CURRENCY"], true);
         $arItem["WEIGHT"] = doubleval($arItem["WEIGHT"]);
         $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit;
         if (CSaleBasketHelper::isSetItem($arItem)) {
             $arSetParentWeight[$arItem["SET_PARENT_ID"]] += $arItem["WEIGHT"] * $arItem["QUANTITY"];
         }
         if (isset($arProductData[$arItem['PRODUCT_ID']]) && is_array($arProductData[$arItem['PRODUCT_ID']])) {
             foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value) {
                 if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields)) {
                     $arItem[$key] = $value;
                 }
             }
         }
         if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) {
             $arFieldsToFill = array_merge($this->arCustomSelectFields, $arImgFields);
             // fields to be filled with parents' values if empty
             foreach ($arFieldsToFill as $field) {
                 $fieldVal = in_array($field, $arImgFields) ? $field : $field . "_VALUE";
                 $parentId = $arSku2Parent[$arItem["PRODUCT_ID"]];
                 if ((!isset($arItem[$fieldVal]) || isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) {
                     $arItem[$fieldVal] = $arProductData[$parentId][$fieldVal];
                 }
             }
         }
         foreach ($arItem as $key => $value) {
             if (strpos($key, "PROPERTY_", 0) === 0 && strrpos($key, "_VALUE") == strlen($key) - 6) {
                 $code = str_replace(array("PROPERTY_", "_VALUE"), "", $key);
                 $propData = $this->arIblockProps[$code];
                 $arItem[$key] = CSaleHelper::getIblockPropInfo($value, $propData);
             }
         }
         $arItem["PREVIEW_PICTURE_SRC"] = "";
         if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0) {
             $arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]);
             if ($arImage) {
                 $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                 $arItem["PREVIEW_PICTURE_SRC"] = $arFileTmp["src"];
             }
         }
         $arItem["DETAIL_PICTURE_SRC"] = "";
         if (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0) {
             $arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]);
             if ($arImage) {
                 $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                 $arItem["DETAIL_PICTURE_SRC"] = $arFileTmp["src"];
             }
         }
     }
     unset($arItem);
     // get sku props data
     if (!empty($arBasketItems) && self::$catalogIncluded && isset($this->offersProps) && !empty($this->offersProps)) {
         $arBasketItems = $this->getSkuPropsData($arBasketItems, $arParents, $this->offersProps);
     }
     // count weight for set parent products
     foreach ($arBasketItems as &$arItem) {
         if (CSaleBasketHelper::isSetParent($arItem)) {
             $arItem["WEIGHT"] = $arSetParentWeight[$arItem["ID"]] / $arItem["QUANTITY"];
             $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit;
         }
     }
     if (isset($arItem)) {
         unset($arItem);
     }
     // fill item arrays for old templates
     foreach ($arBasketItems as &$arItem) {
         if (CSaleBasketHelper::isSetItem($arItem)) {
             continue;
         }
         $arItem['DISCOUNT_PRICE'] = (double) $arItem['DISCOUNT_PRICE'];
         $arItem['PRICE'] = (double) $arItem['PRICE'];
         $arItem['DISCOUNT_PRICE_PERCENT'] = 0;
         $arItem['DISCOUNT_PRICE_PERCENT_FORMATED'] = '';
         $arItem['FULL_PRICE'] = $arItem['PRICE'];
         if ($arItem['DISCOUNT_PRICE'] > 0) {
             if ($arItem['DISCOUNT_PRICE'] + $arItem['PRICE'] > 0) {
                 $arItem['DISCOUNT_PRICE_PERCENT'] = $arItem['DISCOUNT_PRICE'] * 100 / ($arItem['DISCOUNT_PRICE'] + $arItem['PRICE']);
                 $arItem['DISCOUNT_PRICE_PERCENT_FORMATED'] = roundEx($arItem['DISCOUNT_PRICE_PERCENT'], SALE_VALUE_PRECISION) . '%';
                 $arItem['FULL_PRICE'] = $arItem["PRICE"] + $arItem["DISCOUNT_PRICE"];
             }
         }
         $arItem['FULL_PRICE_FORMATED'] = CCurrencyLang::CurrencyFormat($arItem['FULL_PRICE'], $arItem['CURRENCY'], true);
         if ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "N") {
             $allSum += $arItem["PRICE"] * $arItem["QUANTITY"];
             $allWeight += $arItem["WEIGHT"] * $arItem["QUANTITY"];
             $allVATSum += roundEx($arItem["PRICE_VAT_VALUE"] * $arItem["QUANTITY"], SALE_VALUE_PRECISION);
             $bShowReady = true;
             if ($arItem["DISCOUNT_PRICE"] > 0) {
                 $DISCOUNT_PRICE_ALL += $arItem["DISCOUNT_PRICE"] * $arItem["QUANTITY"];
             }
             $arResult["ITEMS"]["AnDelCanBuy"][] = $arItem;
         } elseif ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "Y") {
             $bShowDelay = true;
             $arResult["ITEMS"]["DelDelCanBuy"][] = $arItem;
         } elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y") {
             $bShowSubscribe = true;
             $arResult["ITEMS"]["ProdSubscribe"][] = $arItem;
         } else {
             $bShowNotAvail = true;
             $arItem["NOT_AVAILABLE"] = true;
             $arResult["ITEMS"]["nAnCanBuy"][] = $arItem;
         }
     }
     unset($arItem);
     $arResult["ShowReady"] = $bShowReady ? "Y" : "N";
     $arResult["ShowDelay"] = $bShowDelay ? "Y" : "N";
     $arResult["ShowNotAvail"] = $bShowNotAvail ? "Y" : "N";
     $arResult["ShowSubscribe"] = $bShowSubscribe ? "Y" : "N";
     $arOrder = array('SITE_ID' => SITE_ID, 'USER_ID' => $GLOBALS["USER"]->GetID(), 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"]);
     $arOptions = array('COUNT_DISCOUNT_4_ALL_QUANTITY' => $this->countDiscount4AllQuantity);
     $arErrors = array();
     CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors);
     if (isset($arOrder['ORDER_PRICE'])) {
         $roundOrderFields = CSaleOrder::getRoundFields();
         foreach ($arOrder as $fieldName => $fieldValue) {
             if (in_array($fieldName, $roundOrderFields)) {
                 $arOrder[$fieldName] = roundEx($arOrder[$fieldName], SALE_VALUE_PRECISION);
             }
         }
     }
     if (!empty($arOrder['BASKET_ITEMS']) && is_array($arOrder['BASKET_ITEMS'])) {
         $arOrder['ORDER_PRICE'] = 0;
         $roundBasketFields = CSaleBasket::getRoundFields();
         foreach ($arOrder['BASKET_ITEMS'] as &$basketItem) {
             foreach ($basketItem as $fieldName => $fieldValue) {
                 if (in_array($fieldName, $roundBasketFields)) {
                     if (isset($basketItem[$fieldName])) {
                         $basketItem[$fieldName] = roundEx($basketItem[$fieldName], SALE_VALUE_PRECISION);
                     }
                 }
             }
             $arOrder['ORDER_PRICE'] += $basketItem['PRICE'] * $basketItem['QUANTITY'];
         }
         $arOrder['ORDER_PRICE'] = roundEx($arOrder['ORDER_PRICE'], SALE_VALUE_PRECISION);
     }
     $allSum = 0;
     $allWeight = 0;
     $allVATSum = 0;
     $DISCOUNT_PRICE_ALL = 0;
     $priceWithoutDiscount = 0;
     foreach ($arOrder["BASKET_ITEMS"] as &$arOneItem) {
         $allWeight += $arOneItem["WEIGHT"] * $arOneItem["QUANTITY"];
         $allSum += $arOneItem["PRICE"] * $arOneItem["QUANTITY"];
         if (array_key_exists('VAT_VALUE', $arOneItem)) {
             $arOneItem["PRICE_VAT_VALUE"] = $arOneItem["VAT_VALUE"];
         }
         $allVATSum += roundEx($arOneItem["PRICE_VAT_VALUE"] * $arOneItem["QUANTITY"], SALE_VALUE_PRECISION);
         $arOneItem["PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arOneItem["PRICE"], $arOneItem["CURRENCY"], true);
         $arOneItem["FULL_PRICE"] = $arOneItem["PRICE"] + $arOneItem["DISCOUNT_PRICE"];
         $arOneItem["FULL_PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arOneItem["FULL_PRICE"], $arOneItem["CURRENCY"], true);
         $arOneItem["SUM"] = CCurrencyLang::CurrencyFormat($arOneItem["PRICE"] * $arOneItem["QUANTITY"], $arOneItem["CURRENCY"], true);
         if (0 < doubleval($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"])) {
             $arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"] * 100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]);
         } else {
             $arOneItem["DISCOUNT_PRICE_PERCENT"] = 0;
         }
         $arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%";
         $DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"];
     }
     unset($arOneItem);
     $arResult["ITEMS"]["AnDelCanBuy"] = $arOrder["BASKET_ITEMS"];
     // fill grid data (for new templates with custom columns)
     foreach ($arResult["ITEMS"] as $type => $arItems) {
         foreach ($arItems as $k => $arItem) {
             $arResult["GRID"]["ROWS"][$arItem["ID"]] = $arItem;
         }
     }
     $arResult["allSum"] = roundEx($allSum, SALE_VALUE_PRECISION);
     $arResult["allWeight"] = $allWeight;
     $arResult["allWeight_FORMATED"] = roundEx(doubleval($allWeight / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit;
     $arResult["allSum_FORMATED"] = CCurrencyLang::CurrencyFormat($allSum, $allCurrency, true);
     $arResult["DISCOUNT_PRICE_FORMATED"] = CCurrencyLang::CurrencyFormat($arResult["DISCOUNT_PRICE"], $allCurrency, true);
     $arResult["PRICE_WITHOUT_DISCOUNT"] = CCurrencyLang::CurrencyFormat($allSum + $DISCOUNT_PRICE_ALL, $allCurrency, true);
     if ($this->priceVatShowValue == 'Y') {
         $arResult["allVATSum"] = roundEx($allVATSum, SALE_VALUE_PRECISION);
         $arResult["allVATSum_FORMATED"] = CCurrencyLang::CurrencyFormat($allVATSum, $allCurrency, true);
         $arResult["allSum_wVAT_FORMATED"] = CCurrencyLang::CurrencyFormat(doubleval($arResult["allSum"] - $allVATSum), $allCurrency, true);
     }
     $arResult['COUPON_LIST'] = array();
     $arResult['COUPON'] = '';
     if ($this->hideCoupon != "Y") {
         $arCoupons = DiscountCouponsManager::get(true, array(), true, true);
         if (!empty($arCoupons)) {
             foreach ($arCoupons as &$oneCoupon) {
                 if ($arResult['COUPON'] == '') {
                     $arResult['COUPON'] = $oneCoupon['COUPON'];
                 }
                 if ($oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_NOT_FOUND || $oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_FREEZE) {
                     $oneCoupon['JS_STATUS'] = 'BAD';
                 } elseif ($oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_NOT_APPLYED || $oneCoupon['STATUS'] == DiscountCouponsManager::STATUS_ENTERED) {
                     $oneCoupon['JS_STATUS'] = 'ENTERED';
                 } else {
                     $oneCoupon['JS_STATUS'] = 'APPLYED';
                 }
                 $oneCoupon['JS_CHECK_CODE'] = '';
                 if (isset($oneCoupon['CHECK_CODE_TEXT'])) {
                     $oneCoupon['JS_CHECK_CODE'] = is_array($oneCoupon['CHECK_CODE_TEXT']) ? implode('<br>', $oneCoupon['CHECK_CODE_TEXT']) : $oneCoupon['CHECK_CODE_TEXT'];
                 }
                 $arResult['COUPON_LIST'][] = $oneCoupon;
             }
             unset($oneCoupon);
             $arResult['COUPON_LIST'] = array_values($arCoupons);
         }
         unset($arCoupons);
     }
     if (empty($arBasketItems)) {
         $arResult["ERROR_MESSAGE"] = Loc::getMessage("SALE_EMPTY_BASKET");
     }
     $arResult["DISCOUNT_PRICE_ALL"] = $DISCOUNT_PRICE_ALL;
     $arResult["DISCOUNT_PRICE_ALL_FORMATED"] = CCurrencyLang::CurrencyFormat($DISCOUNT_PRICE_ALL, $allCurrency, true);
     if ($this->usePrepayment == "Y") {
         if (doubleval($arResult["allSum"]) > 0) {
             $personType = array();
             $dbPersonType = CSalePersonType::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("LID" => SITE_ID, "ACTIVE" => "Y"));
             while ($arPersonType = $dbPersonType->Fetch()) {
                 $personType[] = $arPersonType["ID"];
             }
             if (!empty($personType)) {
                 $dbPaySysAction = CSalePaySystemAction::GetList(array(), array("PS_ACTIVE" => "Y", "HAVE_PREPAY" => "Y", "PERSON_TYPE_ID" => $personType), false, false, array("ID", "PAY_SYSTEM_ID", "PERSON_TYPE_ID", "NAME", "ACTION_FILE", "RESULT_FILE", "NEW_WINDOW", "PARAMS", "ENCODING", "LOGOTIP"));
                 if ($arPaySysAction = $dbPaySysAction->Fetch()) {
                     CSalePaySystemAction::InitParamarrays(false, false, $arPaySysAction["PARAMS"]);
                     $pathToAction = $_SERVER["DOCUMENT_ROOT"] . $arPaySysAction["ACTION_FILE"];
                     $pathToAction = str_replace("\\", "/", $pathToAction);
                     while (substr($pathToAction, strlen($pathToAction) - 1, 1) == "/") {
                         $pathToAction = substr($pathToAction, 0, strlen($pathToAction) - 1);
                     }
                     if (file_exists($pathToAction)) {
                         if (is_dir($pathToAction) && file_exists($pathToAction . "/pre_payment.php")) {
                             $pathToAction .= "/pre_payment.php";
                         }
                         try {
                             include_once $pathToAction;
                         } catch (\Bitrix\Main\SystemException $e) {
                             if ($e->getCode() == CSalePaySystemAction::GET_PARAM_VALUE) {
                                 $message = Loc::getMessage("SOA_TEMPL_ORDER_PS_ERROR");
                             } else {
                                 $message = $e->getMessage();
                             }
                             $arResult["ERROR_MESSAGE"] = $message;
                         }
                         $psPreAction = new CSalePaySystemPrePayment();
                         if ($psPreAction->init()) {
                             $orderData = array("PATH_TO_ORDER" => $this->pathToOrder, "AMOUNT" => $arResult["allSum"], "BASKET_ITEMS" => $arResult["ITEMS"]["AnDelCanBuy"]);
                             if (!$psPreAction->BasketButtonAction($orderData)) {
                                 if ($e = $APPLICATION->GetException()) {
                                     $arResult["WARNING_MESSAGE"][] = $e->GetString();
                                 }
                             }
                             $arResult["PREPAY_BUTTON"] = $psPreAction->BasketButtonShow();
                         }
                     }
                 }
             }
         }
     }
     return $arResult;
 }
Exemple #2
0
function getProductDataToFillBasket($productId, $quantity, $userId, $LID, $userColumns, $tmpId = "")
{
	if (!\Bitrix\Main\Loader::includeModule("catalog"))
		return array();

	$arParams = array();

	$productId = (int)$productId;
	if ($productId <= 0)
	{
		return $arParams;
	}
	$iblockId = (int)CIBlockElement::GetIBlockByID($productId);
	if ($iblockId <= 0)
	{
		return $arParams;
	}

	$arSku2Parent = array();
	$arElementId = array();

	$arElementId[] = $productId;
	$arParent = CCatalogSku::GetProductInfo($productId, $iblockId);
	if ($arParent)
	{
		$arElementId[] = $arParent["ID"];
		$arSku2Parent[$productId] = $arParent["ID"];
	}

	$arPropertyInfo = array();
	$userColumns = (string)$userColumns;
	$arUserColumns = ($userColumns != '') ? explode(",", $userColumns) : array();
	foreach ($arUserColumns as $key => $column)
	{
		if (strncmp($column, 'PROPERTY_', 9) != 0)
		{
			unset($arUserColumns[$key]);
		}
		else
		{
			$propertyCode = substr($column, 9);
			if ($propertyCode == '')
			{
				unset($arUserColumns[$key]);
				continue;
			}
			$dbres = CIBlockProperty::GetList(array(), array("CODE" => $propertyCode));
			if ($arPropData = $dbres->GetNext())
				$arPropertyInfo[$column] = $arPropData;
		}
	}

	$arSelect = array_merge(
		array("ID", "NAME", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE", "DETAIL_PAGE_URL", "XML_ID", "IBLOCK_XML_ID"),
		$arUserColumns
	);

	$arProductData = getProductProps($arElementId, $arSelect);

	$defaultMeasure = CCatalogMeasure::getDefaultMeasure(true, true);

	if (!empty($arProductData))
	{
		$arElementInfo = array();
		foreach ($arProductData as $elemId => &$arElement)
		{
			foreach ($arElement as $key => $value)
			{
				if (strncmp($key, 'PROPERTY_', 9) == 0 && substr($key, -6) == "_VALUE")
				{
					$columnCode = str_replace("_VALUE", "", $key);
					$arElement[$key] = getIblockPropInfo($value, $arPropertyInfo[$columnCode], array("WIDTH" => 90, "HEIGHT" => 90));
				}
			}
		}
		unset($arElement);

		if (isset($arProductData[$productId]))
			$arElementInfo = $arProductData[$productId];

		if (isset( $arSku2Parent[$productId]))
			$arParent = $arProductData[$arSku2Parent[$productId]];

		if (!empty($arSku2Parent)) // if sku element doesn't have value of some property - we'll show parent element value instead
		{
			foreach ($arUserColumns as $field)
			{
				$fieldVal = $field."_VALUE";
				$parentId = $arSku2Parent[$productId];

				if ((!isset($arElementInfo[$fieldVal]) || (isset($arElementInfo[$fieldVal]) && strlen($arElementInfo[$fieldVal]) == 0))
					&& (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) // can be array or string
				{
					$arElementInfo[$fieldVal] = $arProductData[$parentId][$fieldVal];
				}
			}
			if (strpos($arElementInfo["~XML_ID"], '#') === false)
			{
				$arElementInfo["~XML_ID"] = $arParent['~XML_ID'].'#'.$arElementInfo["~XML_ID"];
			}
		}

		$arElementInfo["MODULE"] = "catalog";
		$arElementInfo["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider";

		$arElementInfo["PRODUCT_ID"] = $arElementInfo["ID"];

		if ($arElementInfo["IBLOCK_ID"] > 0)
		{
			$arElementInfo["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink($arElementInfo["IBLOCK_ID"], $arElementInfo["PRODUCT_ID"], array(
				"find_section_section" => $arElementInfo["IBLOCK_SECTION_ID"],
				'WF' => 'Y',
			));
		}

		$arBuyerGroups = CUser::GetUserGroup($userId);

		// price
		$arPrice = CCatalogProduct::GetOptimalPrice($arElementInfo["ID"], 1, $arBuyerGroups, "N", array(), $LID);
		$currentPrice = $arPrice["DISCOUNT_PRICE"];
		$arElementInfo["PRICE"] = $currentPrice;
		$arElementInfo["CURRENCY"] = $arPrice["PRICE"]["CURRENCY"];
		$arElementInfo["DISCOUNT_PRICE"] = $arPrice["PRICE"]["PRICE"] - $arPrice["DISCOUNT_PRICE"];
		$currentTotalPrice = ($arElementInfo["PRICE"] + $arElementInfo["DISCOUNT_PRICE"]);
		$discountPercent = 0;
		if ($arElementInfo["DISCOUNT_PRICE"] > 0)
			$discountPercent = intval(($arElementInfo["DISCOUNT_PRICE"] * 100) / $currentTotalPrice);

		$rsProducts = CCatalogProduct::GetList(
			array(),
			array('ID' => $productId),
			false,
			false,
			array('ID', 'QUANTITY', 'WEIGHT', 'MEASURE', 'TYPE', 'BARCODE_MULTI')
		);
		if (!($arProduct = $rsProducts->Fetch()))
		{
			return array();
		}
		$balance = floatval($arProduct["QUANTITY"]);

		// sku props
		$arSkuData = array();
		$arProps[] = array(
			"NAME" => "Catalog XML_ID",
			"CODE" => "CATALOG.XML_ID",
			"VALUE" => $arElementInfo['~IBLOCK_XML_ID']
		);
		$arSkuProperty = CSaleProduct::GetProductSkuProps($productId, '', true);
		if (!empty($arSkuProperty))
		{
			foreach ($arSkuProperty as &$val)
			{
				$arSkuData[] = array(
					'NAME' => $val['NAME'],
					'VALUE' => $val['VALUE'],
					'CODE' => $val['CODE']
				);
			}
			unset($val);
		}
		$arSkuData[] = array(
			"NAME" => "Product XML_ID",
			"CODE" => "PRODUCT.XML_ID",
			"VALUE" => $arElementInfo["~XML_ID"]
		);

		// currency
		$arCurFormat = CCurrencyLang::GetCurrencyFormat($arElementInfo["CURRENCY"]);
		$priceValutaFormat = str_replace("#", "", $arCurFormat["FORMAT_STRING"]);

		$arElementInfo["WEIGHT"] = $arProduct["WEIGHT"];

		// measure
		$arElementInfo["MEASURE_TEXT"] = "";
		if ((int)$arProduct["MEASURE"] > 0)
		{
			$dbMeasure = CCatalogMeasure::GetList(array(), array("ID" => intval($arProduct["MEASURE"])), false, false, array("ID", "SYMBOL_RUS", "SYMBOL_INTL"));
			if ($arMeasure = $dbMeasure->Fetch())
				$arElementInfo["MEASURE_TEXT"] = ($arMeasure["SYMBOL_RUS"] != '' ? $arMeasure["SYMBOL_RUS"] : $arMeasure["SYMBOL_INTL"]);
		}
		if ($arElementInfo["MEASURE_TEXT"] == '')
		{
			$arElementInfo["MEASURE_TEXT"] = ($defaultMeasure["SYMBOL_RUS"] != '' ? $defaultMeasure["SYMBOL_RUS"] : $defaultMeasure["SYMBOL_INTL"]);
		}


		// ratio
		$arElementInfo["RATIO"] = 1;
		$dbratio = CCatalogMeasureRatio::GetList(array(), array("PRODUCT_ID" => $productId));
		if ($arRatio = $dbratio->Fetch())
			$arElementInfo["RATIO"] = $arRatio["RATIO"];

		// image
		if ($arElementInfo["PREVIEW_PICTURE"] > 0)
			$imgCode = $arElementInfo["PREVIEW_PICTURE"];
		elseif ($arElementInfo["DETAIL_PICTURE"] > 0)
			$imgCode = $arElementInfo["DETAIL_PICTURE"];

		if ($imgCode == "" && count($arParent) > 0)
		{
			if ($arParent["PREVIEW_PICTURE"] > 0)
				$imgCode = $arParent["PREVIEW_PICTURE"];
			elseif ($arParent["DETAIL_PICTURE"] > 0)
				$imgCode = $arParent["DETAIL_PICTURE"];
		}

		if ($imgCode > 0)
		{
			$arFile = CFile::GetFileArray($imgCode);
			$arImgProduct = CFile::ResizeImageGet($arFile, array('width'=>80, 'height'=>80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
			if (is_array($arImgProduct))
				$imgUrl = $arImgProduct["src"];
		}

		$arSetInfo = array();
		$arStores = array();

		/** @var $productProvider IBXSaleProductProvider */
		if ($productProvider = CSaleBasket::GetProductProvider(array("MODULE" => $arElementInfo["MODULE"], "PRODUCT_PROVIDER_CLASS" => $arElementInfo["PRODUCT_PROVIDER_CLASS"])))
		{
			// get set items if it is set
			if ($arProduct["TYPE"] == CCatalogProduct::TYPE_SET)
			{
				if (method_exists($productProvider, "GetSetItems"))
				{
					$arSets = $productProvider::GetSetItems($productId, CSaleBasket::TYPE_SET);

					if ($tmpId == "")
						$tmpId = randString(7);

					if (!empty($arSets))
					{
						foreach ($arSets as $arSetData)
						{
							foreach ($arSetData["ITEMS"] as $setItem)
							{
								$arSetItemParams = getProductDataToFillBasket($setItem["PRODUCT_ID"], $setItem["QUANTITY"], $userId, $LID, $userColumns, $tmpId); // recursive call

								// re-define some fields with set data values
								$arSetItemParams["id"] = $setItem["PRODUCT_ID"];
								$arSetItemParams["name"] = $setItem["NAME"];
								$arSetItemParams["module"] = $setItem["MODULE"];
								$arSetItemParams["productProviderClass"] = $setItem["PRODUCT_PROVIDER_CLASS"];
								$arSetItemParams["url"] = $setItem["DETAIL_PAGE_URL"];
								$arSetItemParams["quantity"] = $setItem["QUANTITY"] * $quantity;
								$arSetItemParams["barcodeMulti"] = $setItem["BARCODE_MULTI"];
								$arSetItemParams["productType"] = $setItem["TYPE"];
								$arSetItemParams["weight"] = $setItem["WEIGHT"];
								$arSetItemParams["vatRate"] = $setItem["VAT_RATE"];
								$arSetItemParams["setItems"] = "";

								$arSetItemParams["setParentId"] = $productId."_tmp".$tmpId;
								$arSetItemParams["isSetItem"] = "Y";
								$arSetItemParams["isSetParent"] = "N";

								$arSetInfo[] = $arSetItemParams;
							}
						}
					}
				}
			}

			// get stores
			$storeCount = $productProvider::GetStoresCount(array("SITE_ID" => $LID)); // with exact SITE_ID or SITE_ID = NULL

			if ($storeCount > 0)
			{
				if ($arProductStore = $productProvider::GetProductStores(array("PRODUCT_ID" => $productId, "SITE_ID" => $LID)))
					$arStores = $arProductStore;
			}
		}

		$currentTotalPrice = (float)$currentTotalPrice;
		// params array
		$arParams["id"] = $productId;
		$arParams["name"] = $arElementInfo["~NAME"];
		$arParams["url"] = htmlspecialcharsex($arElementInfo["~DETAIL_PAGE_URL"]);
		$arParams["urlEdit"] = $arElementInfo["EDIT_PAGE_URL"];
		$arParams["urlImg"] = $imgUrl;
		$arParams["price"] = floatval($arElementInfo["PRICE"]);
		$arParams["priceBase"] = $currentTotalPrice;
		$arParams["priceBaseFormat"] = CCurrencyLang::CurrencyFormat($currentTotalPrice, $arElementInfo["CURRENCY"], false);
		$arParams["priceFormated"] = CCurrencyLang::CurrencyFormat(floatval($arElementInfo["PRICE"]), $arElementInfo["CURRENCY"], false);
		$arParams["valutaFormat"] = $priceValutaFormat;
		$arParams["dimensions"] = serialize(array("WIDTH" => $arElementInfo["WIDTH"], "HEIGHT" => $arElementInfo["HEIGHT"], "LENGTH" => $arElementInfo["LENGTH"]));
		$arParams["priceDiscount"] = floatval($arElementInfo["DISCOUNT_PRICE"]);
		$arParams["priceTotalFormated"] = CCurrencyLang::CurrencyFormat($currentTotalPrice, $arElementInfo["CURRENCY"], true);
		$arParams["discountPercent"] = $discountPercent;
		$arParams["summaFormated"] = CCurrencyLang::CurrencyFormat($arElementInfo["PRICE"], $arElementInfo["CURRENCY"], false);
		$arParams["quantity"] = $quantity;
		$arParams["module"] = $arElementInfo["MODULE"];
		$arParams["currency"] = $arElementInfo["CURRENCY"];
		$arParams["weight"] = $arElementInfo["WEIGHT"];
		$arParams["vatRate"] = $arPrice["PRICE"]["VAT_RATE"];
		$arParams["priceType"] = $arPrice["PRICE"]["CATALOG_GROUP_NAME"];
		$arParams["balance"] = $balance;
		$arParams["notes"] = (is_array($arPrice["PRICE"]) && array_key_exists("CATALOG_GROUP_NAME", $arPrice["PRICE"])) ? $arPrice["PRICE"]["CATALOG_GROUP_NAME"] : "";
		$arParams["catalogXmlID"] = $arElementInfo["~IBLOCK_XML_ID"];
		$arParams["productXmlID"] = $arElementInfo["~XML_ID"];
		$arParams["callback"] = "";
		$arParams["orderCallback"] = "";
		$arParams["cancelCallback"] = "";
		$arParams["payCallback"] = "";
		$arParams["productProviderClass"] = $arElementInfo["PRODUCT_PROVIDER_CLASS"];
		$arParams["skuProps"] = $arSkuData;
		$arParams["measureText"] = $arElementInfo["MEASURE_TEXT"];
		$arParams["ratio"] = $arElementInfo["RATIO"];
		$arParams["barcodeMulti"] = $arProduct["BARCODE_MULTI"];

		$arParams["productType"] = empty($arSetInfo) ? "" : CSaleBasket::TYPE_SET;
		$arParams["setParentId"] = empty($arSetInfo) ? "" : $productId."_tmp".$tmpId;

		$arParams["setItems"] = $arSetInfo;
		$arParams["isSetItem"] = "N";
		$arParams["isSetParent"] = empty($arSetInfo) ? "N" : "Y";

		$arParams["stores"] = empty($arSetInfo) ? $arStores : array();
		$arParams["productPropsValues"] = $arElementInfo; // along with other information also contains values of properties with correct keys (after getProductProps)
	}

	return $arParams;
}
Exemple #3
0
			$arCustomSelectFields[] = $columnCode;

			$dbres = CIBlockProperty::GetList(array(), array("CODE" => substr($columnCode, 9)));
			if ($arPropData = $dbres->GetNext())
				$arIblockProps[$columnCode] = $arPropData;

			$count++;
		}
	}
}

if (!empty($arElementId))
{
	$arSelect = array_merge(array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "IBLOCK_TYPE_ID", "PREVIEW_PICTURE", "DETAIL_PICTURE"), $arCustomSelectFields);

	$arProductData = getProductProps($arElementId, $arSelect);
}

$productWeight = 0.0;
foreach ($arBasketItem as $key => &$arItem)
{
	if (!empty($arProductData[$arItem["PRODUCT_ID"]]))
	{
		if ($arItem["MODULE"] == "catalog" && $bUseIblock)
		{
			$arBasketItem[$key]["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink($arProductData[$arItem["PRODUCT_ID"]]["IBLOCK_ID"], $arItem["PRODUCT_ID"], array(
				"find_section_section" => $arProductData[$arItem["PRODUCT_ID"]]["IBLOCK_SECTION_ID"],
				'WF' => 'Y',
			));
		}
Exemple #4
0
 /**
  * @param $productId
  * @param $quantity
  * @param $userId
  * @param $LID
  * @param $userColumns
  * @param string $tmpId we can suggest that this mean the set_item
  * @return array
  * @throws Main\LoaderException
  */
 protected function getProductDataToFillBasket($productId, $quantity, $userId, $LID, $userColumns, $tmpId = "")
 {
     $isSetItem = $tmpId != "";
     if (self::$catalogIncluded === null) {
         self::$catalogIncluded = Main\Loader::includeModule('catalog');
     }
     if (!self::$catalogIncluded) {
         return array();
     }
     $arParams = array();
     static $proxyIblockElement = array();
     static $proxyCatalogMeasure = array();
     static $proxyParent = array();
     static $proxyIblockProperty = array();
     static $proxyProductData = array();
     static $proxyCatalogProduct = array();
     static $proxyCatalogMeasureRatio = array();
     $productId = (int) $productId;
     if ($productId <= 0) {
         return $arParams;
     }
     if (!empty($proxyIblockElement[$productId])) {
         $iblockId = $proxyIblockElement[$productId];
     } else {
         $iblockId = (int) \CIBlockElement::getIBlockByID($productId);
         if ($iblockId > 0) {
             $proxyIblockElement[$productId] = $iblockId;
         }
     }
     if ($iblockId <= 0) {
         return $arParams;
     }
     $arSku2Parent = array();
     $arElementId = array();
     $arElementId[] = $productId;
     $proxyParentKey = $productId . "|" . $iblockId;
     if (!empty($proxyParent[$proxyParentKey]) && is_array($proxyParent[$proxyParentKey])) {
         $arParent = $proxyParent[$proxyParentKey];
     } else {
         $arParent = \CCatalogSku::getProductInfo($productId, $iblockId);
         $proxyParent[$proxyParentKey] = $arParent;
     }
     if ($arParent) {
         $arElementId[] = $arParent["ID"];
         $arSku2Parent[$productId] = $arParent["ID"];
     }
     $arPropertyInfo = array();
     $userColumns = (string) $userColumns;
     $arUserColumns = $userColumns != '' ? explode(",", $userColumns) : array();
     foreach ($arUserColumns as $key => $column) {
         if (strncmp($column, 'PROPERTY_', 9) != 0) {
             unset($arUserColumns[$key]);
         } else {
             $propertyCode = substr($column, 9);
             if ($propertyCode == '') {
                 unset($arUserColumns[$key]);
                 continue;
             }
             if (!empty($proxyIblockProperty[$propertyCode]) && is_array($proxyIblockProperty[$propertyCode])) {
                 $arPropertyInfo[$column] = $proxyIblockProperty[$propertyCode];
             } else {
                 $dbres = \CIBlockProperty::GetList(array(), array("CODE" => $propertyCode));
                 if ($arPropData = $dbres->GetNext()) {
                     $arPropertyInfo[$column] = $arPropData;
                     $proxyIblockProperty[$propertyCode] = $arPropData;
                 }
             }
         }
     }
     $arSelect = array_merge(array("ID", "NAME", "IBLOCK_ID", "IBLOCK_SECTION_ID", "DETAIL_PICTURE", "PREVIEW_PICTURE", "XML_ID", "IBLOCK_XML_ID"), $arUserColumns);
     $proxyProductDataKey = md5(join('|', $arElementId) . "_" . join('|', $arSelect));
     if (!empty($proxyProductData[$proxyProductDataKey]) && is_array($proxyProductData[$proxyProductDataKey])) {
         $arProductData = $proxyProductData[$proxyProductDataKey];
     } else {
         $arProductData = getProductProps($arElementId, $arSelect);
         $proxyProductData[$proxyProductDataKey] = $arProductData;
     }
     $defaultMeasure = \CCatalogMeasure::getDefaultMeasure(true, true);
     if (!empty($arProductData)) {
         $arElementInfo = array();
         foreach ($arProductData as $elemId => &$arElement) {
             foreach ($arElement as $key => $value) {
                 if (strncmp($key, 'PROPERTY_', 9) == 0 && substr($key, -6) == "_VALUE") {
                     $columnCode = str_replace("_VALUE", "", $key);
                     $arElement[$key] = getIblockPropInfo($value, $arPropertyInfo[$columnCode], array("WIDTH" => 90, "HEIGHT" => 90));
                 }
             }
         }
         unset($arElement);
         if (isset($arProductData[$productId])) {
             $arElementInfo = $arProductData[$productId];
         }
         if (isset($arSku2Parent[$productId])) {
             $arParent = $arProductData[$arSku2Parent[$productId]];
         }
         if (!empty($arSku2Parent)) {
             foreach ($arUserColumns as $field) {
                 $fieldVal = $field . "_VALUE";
                 $parentId = $arSku2Parent[$productId];
                 if ((!isset($arElementInfo[$fieldVal]) || isset($arElementInfo[$fieldVal]) && strlen($arElementInfo[$fieldVal]) == 0) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) {
                     $arElementInfo[$fieldVal] = $arProductData[$parentId][$fieldVal];
                 }
             }
             if (strpos($arElementInfo["~XML_ID"], '#') === false) {
                 $arElementInfo["~XML_ID"] = $arParent['~XML_ID'] . '#' . $arElementInfo["~XML_ID"];
             }
         }
         $arElementInfo["MODULE"] = "catalog";
         $arElementInfo["PRODUCT_PROVIDER_CLASS"] = "CCatalogProductProvider";
         $arElementInfo["PRODUCT_ID"] = $arElementInfo["ID"];
         if ($arElementInfo["IBLOCK_ID"] > 0) {
             $arElementInfo["EDIT_PAGE_URL"] = \CIBlock::GetAdminElementEditLink($arElementInfo["IBLOCK_ID"], $arElementInfo["PRODUCT_ID"], array("find_section_section" => $arElementInfo["IBLOCK_SECTION_ID"], 'WF' => 'Y'));
         }
         static $buyersGroups = array();
         if (empty($buyersGroups[$userId])) {
             $buyersGroups[$userId] = \CUser::getUserGroup($userId);
         }
         $arBuyerGroups = $buyersGroups[$userId];
         // price
         $currentVatMode = \CCatalogProduct::getPriceVatIncludeMode();
         $currentUseDiscount = \CCatalogProduct::getUseDiscount();
         \CCatalogProduct::setUseDiscount(!$isSetItem);
         \CCatalogProduct::setPriceVatIncludeMode(true);
         \CCatalogProduct::setUsedCurrency(Sale\Internals\SiteCurrencyTable::getSiteCurrency($LID));
         $arPrice = \CCatalogProduct::getOptimalPrice($arElementInfo["ID"], 1, $arBuyerGroups, "N", array(), $LID);
         \CCatalogProduct::clearUsedCurrency();
         \CCatalogProduct::setPriceVatIncludeMode($currentVatMode);
         \CCatalogProduct::setUseDiscount($currentUseDiscount);
         unset($currentUseDiscount, $currentVatMode);
         $currentPrice = $arPrice['RESULT_PRICE']['DISCOUNT_PRICE'];
         $arElementInfo['PRICE'] = $currentPrice;
         $arElementInfo['CURRENCY'] = $arPrice['RESULT_PRICE']['CURRENCY'];
         $currentTotalPrice = $arPrice['RESULT_PRICE']['BASE_PRICE'];
         $arProduct = array();
         if (!empty($proxyCatalogProduct[$productId]) && is_array($proxyCatalogProduct[$productId])) {
             $arProduct = $proxyCatalogProduct[$productId];
         } else {
             $rsProducts = \CCatalogProduct::getList(array(), array('ID' => $productId), false, false, array('ID', 'QUANTITY', 'WEIGHT', 'MEASURE', 'TYPE', 'BARCODE_MULTI'));
             if ($arProduct = $rsProducts->Fetch()) {
                 $proxyCatalogProduct[$productId] = $arProduct;
             }
         }
         if (empty($arProduct) || !is_array($arProduct)) {
             return array();
         }
         $balance = floatval($arProduct["QUANTITY"]);
         // sku props
         $arSkuData = array();
         $arProps[] = array("NAME" => "Catalog XML_ID", "CODE" => "CATALOG.XML_ID", "VALUE" => $arElementInfo['~IBLOCK_XML_ID']);
         static $proxySkuProperty = array();
         if (!empty($proxySkuProperty[$productId]) && is_array($proxySkuProperty[$productId])) {
             $arSkuProperty = $proxySkuProperty[$productId];
         } else {
             $arSkuProperty = \CSaleProduct::GetProductSkuProps($productId, '', true);
             $proxySkuProperty[$productId] = $arSkuProperty;
         }
         if (!empty($arSkuProperty)) {
             foreach ($arSkuProperty as &$val) {
                 $arSkuData[] = array('NAME' => $val['NAME'], 'VALUE' => $val['VALUE'], 'CODE' => $val['CODE']);
             }
             unset($val);
         }
         $arSkuData[] = array("NAME" => "Product XML_ID", "CODE" => "PRODUCT.XML_ID", "VALUE" => $arElementInfo["~XML_ID"]);
         $arElementInfo["WEIGHT"] = $arProduct["WEIGHT"];
         // measure
         $arElementInfo["MEASURE_TEXT"] = "";
         $arElementInfo["MEASURE_CODE"] = 0;
         if ((int) $arProduct["MEASURE"] > 0) {
             if (!empty($proxyCatalogMeasure[$arProduct["MEASURE"]]) && is_array($proxyCatalogMeasure[$arProduct["MEASURE"]])) {
                 $arMeasure = $proxyCatalogMeasure[$arProduct["MEASURE"]];
             } else {
                 $dbMeasure = \CCatalogMeasure::GetList(array(), array("ID" => intval($arProduct["MEASURE"])), false, false, array("ID", "SYMBOL_RUS", "SYMBOL_INTL"));
                 if ($arMeasure = $dbMeasure->Fetch()) {
                     $proxyCatalogMeasure[$arProduct["MEASURE"]] = $arMeasure;
                 }
             }
             if (!empty($arMeasure) && is_array($arMeasure)) {
                 $arElementInfo["MEASURE_TEXT"] = $arMeasure["SYMBOL_RUS"] != '' ? $arMeasure["SYMBOL_RUS"] : $arMeasure["SYMBOL_INTL"];
                 $arElementInfo["MEASURE_CODE"] = $arMeasure["CODE"];
             }
         }
         if ($arElementInfo["MEASURE_TEXT"] == '') {
             $arElementInfo["MEASURE_TEXT"] = $defaultMeasure["SYMBOL_RUS"] != '' ? $defaultMeasure["SYMBOL_RUS"] : $defaultMeasure["SYMBOL_INTL"];
         }
         // ratio
         $arElementInfo["RATIO"] = 1;
         if (!empty($proxyCatalogMeasureRatio[$productId]) && is_array($proxyCatalogMeasureRatio[$productId])) {
             $arRatio = $proxyCatalogMeasureRatio[$productId];
         } else {
             $dbratio = \CCatalogMeasureRatio::GetList(array(), array("PRODUCT_ID" => $productId));
             if ($arRatio = $dbratio->Fetch()) {
                 $proxyCatalogMeasureRatio[$productId] = $arRatio;
             }
         }
         if (!empty($arRatio) && is_array($arRatio)) {
             $arElementInfo["RATIO"] = $arRatio["RATIO"];
         }
         // image
         $imgCode = '';
         $imgUrl = '';
         if ($arElementInfo["PREVIEW_PICTURE"] > 0) {
             $imgCode = $arElementInfo["PREVIEW_PICTURE"];
         } elseif ($arElementInfo["DETAIL_PICTURE"] > 0) {
             $imgCode = $arElementInfo["DETAIL_PICTURE"];
         }
         if ($imgCode == "" && count($arParent) > 0) {
             if ($arParent["PREVIEW_PICTURE"] > 0) {
                 $imgCode = $arParent["PREVIEW_PICTURE"];
             } elseif ($arParent["DETAIL_PICTURE"] > 0) {
                 $imgCode = $arParent["DETAIL_PICTURE"];
             }
         }
         if ($imgCode > 0) {
             $arFile = \CFile::GetFileArray($imgCode);
             $arImgProduct = \CFile::ResizeImageGet($arFile, array('width' => 80, 'height' => 80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
             if (is_array($arImgProduct)) {
                 $imgUrl = $arImgProduct["src"];
             }
         }
         $arSetInfo = array();
         $arStores = array();
         /** @var $productProvider IBXSaleProductProvider */
         if ($productProvider = \CSaleBasket::GetProductProvider(array("MODULE" => $arElementInfo["MODULE"], "PRODUCT_PROVIDER_CLASS" => $arElementInfo["PRODUCT_PROVIDER_CLASS"]))) {
             // get set items if it is set
             if ($arProduct["TYPE"] == \CCatalogProduct::TYPE_SET) {
                 if (method_exists($productProvider, "GetSetItems")) {
                     $arSets = $productProvider::GetSetItems($productId, \CSaleBasket::TYPE_SET);
                     if ($tmpId == "") {
                         $tmpId = randString(7);
                     }
                     if (!empty($arSets)) {
                         foreach ($arSets as $arSetData) {
                             foreach ($arSetData["ITEMS"] as $setItem) {
                                 $arSetItemParams = self::getProductDataToFillBasket($setItem["PRODUCT_ID"], $setItem["QUANTITY"], $userId, $LID, $userColumns, $tmpId);
                                 // recursive call
                                 // re-define some fields with set data values
                                 $arSetItemParams["PARENT_OFFER_ID"] = $productId;
                                 $arSetItemParams["OFFER_ID"] = $setItem["PRODUCT_ID"];
                                 $arSetItemParams["NAME"] = $setItem["NAME"];
                                 $arSetItemParams["MODULE"] = $setItem["MODULE"];
                                 $arSetItemParams["PRODUCT_PROVIDER_CLASS"] = $setItem["PRODUCT_PROVIDER_CLASS"];
                                 $arSetItemParams["QUANTITY"] = $setItem["QUANTITY"] * $quantity;
                                 $arSetItemParams["BARCODE_MULTI"] = $setItem["BARCODE_MULTI"];
                                 $arSetItemParams["PRODUCT_TYPE"] = $setItem["TYPE"];
                                 $arSetItemParams["WEIGHT"] = $setItem["WEIGHT"];
                                 $arSetItemParams["VAT_RATE"] = $setItem["VAT_RATE"];
                                 $arSetItemParams["SET_ITEMS"] = "";
                                 $arSetItemParams["OLD_PARENT_ID"] = $productId . "_tmp" . $tmpId;
                                 $arSetItemParams["IS_SET_ITEM"] = "Y";
                                 $arSetItemParams["IS_SET_PARENT"] = "N";
                                 $arSetItemParams["PROVIDER_DATA"] = serialize($setItem);
                                 $arSetInfo[] = $arSetItemParams;
                             }
                         }
                     }
                 }
             }
             // get stores
             $storeCount = $productProvider::GetStoresCount(array("SITE_ID" => $LID));
             // with exact SITE_ID or SITE_ID = NULL
             if ($storeCount > 0) {
                 if ($arProductStore = $productProvider::GetProductStores(array("PRODUCT_ID" => $productId, "SITE_ID" => $LID))) {
                     $arStores = $arProductStore;
                 }
             }
         }
         $currentTotalPrice = (double) $currentTotalPrice;
         // params array
         $arParams["OFFER_ID"] = $productId;
         $arParams["NAME"] = $arElementInfo["~NAME"];
         $arParams["EDIT_PAGE_URL"] = $arElementInfo["EDIT_PAGE_URL"];
         $arParams["DETAIL_PAGE_URL"] = htmlspecialcharsex($arElementInfo["~DETAIL_PAGE_URL"]);
         $arParams["PICTURE_URL"] = $imgUrl;
         $arParams["PRICE"] = floatval($arElementInfo["PRICE"]);
         $arParams["PRICE_BASE"] = $currentTotalPrice;
         $arParams["DIMENSIONS"] = serialize(array("WIDTH" => $arElementInfo["WIDTH"], "HEIGHT" => $arElementInfo["HEIGHT"], "LENGTH" => $arElementInfo["LENGTH"]));
         $arParams["QUANTITY"] = $quantity;
         $arParams["MODULE"] = $arElementInfo["MODULE"];
         $arParams["CURRENCY"] = $arElementInfo["CURRENCY"];
         $arParams["WEIGHT"] = $arElementInfo["WEIGHT"];
         $arParams["VAT_RATE"] = $arPrice["PRICE"]["VAT_RATE"];
         $arParams["PRICE_TYPE"] = $arPrice["PRICE"]["CATALOG_GROUP_NAME"];
         $arParams["AVAILABLE"] = $balance;
         $arParams["NOTES"] = !empty($arPrice["PRICE"]["CATALOG_GROUP_NAME"]) ? $arPrice["PRICE"]["CATALOG_GROUP_NAME"] : "";
         $arParams["CATALOG_XML_ID"] = $arElementInfo["~IBLOCK_XML_ID"];
         $arParams["PRODUCT_XML_ID"] = $arElementInfo["~XML_ID"];
         $arParams["PRODUCT_PROVIDER_CLASS"] = $arElementInfo["PRODUCT_PROVIDER_CLASS"];
         $arParams["PROPS"] = $arSkuData;
         $arParams["MEASURE_TEXT"] = $arElementInfo["MEASURE_TEXT"];
         $arParams["MEASURE_CODE"] = $arElementInfo["MEASURE_CODE"];
         $arParams["MEASURE_RATIO"] = $arElementInfo["RATIO"];
         $arParams["BARCODE_MULTI"] = $arProduct["BARCODE_MULTI"];
         $arParams["PRODUCT_TYPE"] = empty($arSetInfo) ? "" : \CSaleBasket::TYPE_SET;
         $arParams["OLD_PARENT_ID"] = empty($arSetInfo) ? "" : $productId . "_tmp" . $tmpId;
         $arParams["SET_ITEMS"] = $arSetInfo;
         $arParams["IS_SET_ITEM"] = "N";
         $arParams["IS_SET_PARENT"] = empty($arSetInfo) ? "N" : "Y";
         $arParams["STORES"] = empty($arSetInfo) ? $arStores : array();
         $arParams["PRODUCT_PROPS_VALUES"] = $arElementInfo;
         // along with other information also contains values of properties with correct keys (after getProductProps)
     }
     return $arParams;
 }
Exemple #5
0
 private function setImgSrc(&$arBasketItems, $arElementId, $arSku2Parent)
 {
     $arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE");
     $arProductData = getProductProps($arElementId, array("ID") + $arImgFields);
     foreach ($arBasketItems as &$arItem) {
         if (array_key_exists($arItem["PRODUCT_ID"], $arProductData) && is_array($arProductData[$arItem["PRODUCT_ID"]])) {
             foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value) {
                 if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields)) {
                     $arItem[$key] = $value;
                 }
             }
         }
         if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) {
             foreach ($arImgFields as $field) {
                 $fieldVal = in_array($field, $arImgFields) ? $field : $field . "_VALUE";
                 $parentId = $arSku2Parent[$arItem["PRODUCT_ID"]];
                 if ((!isset($arItem[$fieldVal]) || isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) {
                     $arItem[$fieldVal] = $arProductData[$parentId][$fieldVal];
                 }
             }
         }
         $arItem["PICTURE_SRC"] = "";
         $arImage = null;
         if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0) {
             $arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]);
         } elseif (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0) {
             $arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]);
         }
         if ($arImage) {
             $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "70", "height" => "70"), BX_RESIZE_IMAGE_PROPORTIONAL, true);
             $arItem["PICTURE_SRC"] = $arFileTmp["src"];
         }
     }
 }
function getSaleProductImage($product)
{
    $productImg = '';
    if ($product["INFO"]["PREVIEW_PICTURE"] != "") {
        $productImg = $product["INFO"]["PREVIEW_PICTURE"];
    } elseif ($product["INFO"]["DETAIL_PICTURE"] != "") {
        $productImg = $product["INFO"]["DETAIL_PICTURE"];
    }
    if (empty($productImg) && CModule::IncludeModule("catalog")) {
        $arParent = CCatalogSku::GetProductInfo($product["PRODUCT_ID"]);
        if (intval($arParent["ID"]) > 0) {
            $arProductData = getProductProps(array($arParent["ID"]), array("ID", "PREVIEW_PICTURE", "DETAIL_PICTURE", "IBLOCK_TYPE_ID", "IBLOCK_ID", "IBLOCK_SECTION_ID"));
            if (!empty($arProductData[$arParent["ID"]]["PREVIEW_PICTURE"])) {
                $productImg = $arProductData[$arParent["ID"]]["PREVIEW_PICTURE"];
            } elseif (!empty($arProductData[$arParent["ID"]]["DETAIL_PICTURE"])) {
                $productImg = $arProductData[$arParent["ID"]]["DETAIL_PICTURE"];
            }
        }
    }
    if ($productImg != "") {
        $arFile = CFile::GetFileArray($productImg);
        $productImg = CFile::ResizeImageGet($arFile, array('width' => 80, 'height' => 80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
    }
    return $productImg;
}
Exemple #7
0
 public function getBasketItems()
 {
     global $APPLICATION;
     $bUseCatalog = CModule::IncludeModule("catalog");
     $bUseIblock = $bUseCatalog;
     $bShowReady = False;
     $bShowDelay = False;
     $bShowSubscribe = False;
     $bShowNotAvail = False;
     $allSum = 0;
     $allWeight = 0;
     $allCurrency = CSaleLang::GetLangCurrency($this->getSiteId());
     $allVATSum = 0;
     $arParents = array();
     $arResult["ITEMS"]["AnDelCanBuy"] = array();
     $arResult["ITEMS"]["DelDelCanBuy"] = array();
     $arResult["ITEMS"]["nAnCanBuy"] = array();
     $arResult["ITEMS"]["ProdSubscribe"] = array();
     $DISCOUNT_PRICE_ALL = 0;
     // BASKET PRODUCTS (including measures, ratio, iblock properties data)
     $arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE");
     $arBasketItems = array();
     $arSku2Parent = array();
     $arSetParentWeight = array();
     $basketItemsFilter = array("USER_ID" => $this->userId, "ORDER_ID" => "NULL");
     if ($this->showDelay != 'Y') {
         $basketItemsFilter['DELAY'] = 'N';
     }
     $dbItems = CSaleBasket::GetList(array("ID" => "ASC"), $basketItemsFilter, false, false, array("ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY", "PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID", "PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID"));
     while ($arItem = $dbItems->GetNext()) {
         $arBasketItems[] = $arItem;
         if (CSaleBasketHelper::isSetItem($arItem)) {
             continue;
         }
         $arElementId[] = $arItem["PRODUCT_ID"];
         if ($bUseCatalog) {
             $arParent = CCatalogSku::GetProductInfo($arItem["PRODUCT_ID"]);
             if ($arParent) {
                 $arElementId[] = $arParent["ID"];
                 $arSku2Parent[$arItem["PRODUCT_ID"]] = $arParent["ID"];
                 $arParents[$arItem["PRODUCT_ID"]]["PRODUCT_ID"] = $arParent["ID"];
                 $arParents[$arItem["PRODUCT_ID"]]["IBLOCK_ID"] = $arParent["IBLOCK_ID"];
             }
         }
     }
     // get measures, ratio, sku props data and available quantity
     if (!empty($arBasketItems) && $bUseCatalog) {
         $arBasketItems = getMeasures($arBasketItems);
         $arBasketItems = getRatio($arBasketItems);
         $arBasketItems = $this->getAvailableQuantity($arBasketItems);
     }
     // get product properties data
     $arProductData = getProductProps($arElementId, array_merge(array("ID"), $arImgFields, $this->arCustomSelectFields));
     foreach ($arBasketItems as &$arItem) {
         $quantityIsFloat = false;
         if (number_format(doubleval($arItem['QUANTITY']), 2, '.', '') != intval($arItem['QUANTITY'])) {
             $quantityIsFloat = true;
         }
         $arItem["QUANTITY"] = $quantityIsFloat === false && $this->quantityFloat != "Y" ? intval($arItem['QUANTITY']) : number_format(doubleval($arItem['QUANTITY']), 2, '.', '');
         $arItem["QUANTITY_FORMATED"] = $arItem["QUANTITY"] . " " . $arItem["MEASURE_TEXT"];
         $arItem["PROPS"] = array();
         $dbProp = CSaleBasket::GetPropsList(array("SORT" => "ASC", "ID" => "ASC"), array("BASKET_ID" => $arItem["ID"], "!CODE" => array("CATALOG.XML_ID", "PRODUCT.XML_ID")));
         while ($arProp = $dbProp->GetNext()) {
             $arItem["PROPS"][] = $arProp;
         }
         $arItem["PRICE_VAT_VALUE"] = $arItem["PRICE"] / ($arItem["VAT_RATE"] + 1) * $arItem["VAT_RATE"];
         $arItem["PRICE_FORMATED"] = $this->getSaleFormatCurrency($arItem["PRICE"], $arItem["CURRENCY"]);
         $arItem["WEIGHT"] = doubleval($arItem["WEIGHT"]);
         $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit;
         $arItem["DISCOUNT_FORMATED"] = $this->getSaleFormatCurrency($arItem["DISCOUNT_PRICE"], $arItem["CURRENCY"]);
         if (CSaleBasketHelper::isSetItem($arItem)) {
             $arSetParentWeight[$arItem["SET_PARENT_ID"]] += $arItem["WEIGHT"] * $arItem["QUANTITY"];
         }
         if (array_key_exists($arItem["PRODUCT_ID"], $arProductData) && is_array($arProductData[$arItem["PRODUCT_ID"]])) {
             foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value) {
                 if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields)) {
                     $arItem[$key] = $value;
                 }
             }
         }
         if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) {
             $arFieldsToFill = array_merge($this->arCustomSelectFields, $arImgFields);
             // fields to be filled with parents' values if empty
             foreach ($arFieldsToFill as $field) {
                 $fieldVal = in_array($field, $arImgFields) ? $field : $field . "_VALUE";
                 $parentId = $arSku2Parent[$arItem["PRODUCT_ID"]];
                 if ((!isset($arItem[$fieldVal]) || isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0) && (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) {
                     $arItem[$fieldVal] = $arProductData[$parentId][$fieldVal];
                 }
             }
         }
         foreach ($arItem as $key => $value) {
             if (strpos($key, "PROPERTY_", 0) === 0 && strrpos($key, "_VALUE") == strlen($key) - 6) {
                 $code = str_replace(array("PROPERTY_", "_VALUE"), "", $key);
                 $propData = $this->arIblockProps[$code];
                 $arItem[$key] = CSaleHelper::getIblockPropInfo($value, $propData);
             }
         }
         $arItem["PREVIEW_PICTURE_SRC"] = "";
         if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0) {
             $arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]);
             if ($arImage) {
                 $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                 $arItem["PREVIEW_PICTURE_SRC"] = $arFileTmp["src"];
             }
         }
         $arItem["DETAIL_PICTURE_SRC"] = "";
         if (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0) {
             $arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]);
             if ($arImage) {
                 $arFileTmp = CFile::ResizeImageGet($arImage, array("width" => "110", "height" => "110"), BX_RESIZE_IMAGE_PROPORTIONAL, true);
                 $arItem["DETAIL_PICTURE_SRC"] = $arFileTmp["src"];
             }
         }
     }
     unset($arItem);
     // get sku props data
     if (!empty($arBasketItems) && $bUseCatalog && isset($this->offersProps) && !empty($this->offersProps)) {
         $arBasketItems = $this->getSkuPropsData($arBasketItems, $arParents, $this->offersProps);
     }
     // count weight for set parent products
     foreach ($arBasketItems as &$arItem) {
         if (CSaleBasketHelper::isSetParent($arItem)) {
             $arItem["WEIGHT"] = $arSetParentWeight[$arItem["ID"]] / $arItem["QUANTITY"];
             $arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit;
         }
     }
     if (isset($arItem)) {
         unset($arItem);
     }
     // fill item arrays for old templates
     foreach ($arBasketItems as &$arItem) {
         if (CSaleBasketHelper::isSetItem($arItem)) {
             continue;
         }
         if ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "N") {
             $allSum += $arItem["PRICE"] * $arItem["QUANTITY"];
             $allWeight += $arItem["WEIGHT"] * $arItem["QUANTITY"];
             $allVATSum += roundEx($arItem["PRICE_VAT_VALUE"] * $arItem["QUANTITY"], SALE_VALUE_PRECISION);
             $bShowReady = True;
             if (doubleval($arItem["DISCOUNT_PRICE"]) > 0) {
                 if (0 < doubleval($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"])) {
                     $arItem["DISCOUNT_PRICE_PERCENT"] = $arItem["DISCOUNT_PRICE"] * 100 / ($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"]);
                 } else {
                     $arItem["DISCOUNT_PRICE_PERCENT"] = 0;
                 }
                 $arItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%";
                 $DISCOUNT_PRICE_ALL += $arItem["DISCOUNT_PRICE"] * $arItem["QUANTITY"];
             }
             $arResult["ITEMS"]["AnDelCanBuy"][] = $arItem;
         } elseif ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "Y") {
             $bShowDelay = True;
             $arResult["ITEMS"]["DelDelCanBuy"][] = $arItem;
         } elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y") {
             $bShowSubscribe = True;
             $arResult["ITEMS"]["ProdSubscribe"][] = $arItem;
         } else {
             $bShowNotAvail = True;
             $arItem["NOT_AVAILABLE"] = true;
             $arResult["ITEMS"]["nAnCanBuy"][] = $arItem;
         }
     }
     unset($arItem);
     $arResult["ShowReady"] = $bShowReady ? "Y" : "N";
     $arResult["ShowDelay"] = $bShowDelay ? "Y" : "N";
     $arResult["ShowNotAvail"] = $bShowNotAvail ? "Y" : "N";
     $arResult["ShowSubscribe"] = $bShowSubscribe ? "Y" : "N";
     $arOrder = array('SITE_ID' => $this->getSiteId(), 'USER_ID' => $this->userId, 'ORDER_PRICE' => $allSum, 'ORDER_WEIGHT' => $allWeight, 'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"]);
     $arOptions = array('COUNT_DISCOUNT_4_ALL_QUANTITY' => $this->countDiscount4AllQuantity);
     $arErrors = array();
     CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors);
     $allSum = 0;
     $allWeight = 0;
     $allVATSum = 0;
     $DISCOUNT_PRICE_ALL = 0;
     $priceWithoutDiscount = 0;
     foreach ($arOrder["BASKET_ITEMS"] as &$arOneItem) {
         $allWeight += $arOneItem["WEIGHT"] * $arOneItem["QUANTITY"];
         $allSum += $arOneItem["PRICE"] * $arOneItem["QUANTITY"];
         if (array_key_exists('VAT_VALUE', $arOneItem)) {
             $arOneItem["PRICE_VAT_VALUE"] = $arOneItem["VAT_VALUE"];
         }
         $allVATSum += roundEx($arOneItem["PRICE_VAT_VALUE"] * $arOneItem["QUANTITY"], SALE_VALUE_PRECISION);
         $arOneItem["PRICE_FORMATED"] = $this->getSaleFormatCurrency($arOneItem["PRICE"], $arOneItem["CURRENCY"]);
         $arOneItem["FULL_PRICE"] = $arOneItem["PRICE"] + $arOneItem["DISCOUNT_PRICE"];
         $arOneItem["FULL_PRICE_FORMATED"] = $this->getSaleFormatCurrency($arOneItem["FULL_PRICE"], $arOneItem["CURRENCY"]);
         $arOneItem["SUM"] = $this->getSaleFormatCurrency($arOneItem["PRICE"] * $arOneItem["QUANTITY"], $arOneItem["CURRENCY"]);
         if (0 < doubleval($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"])) {
             $arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"] * 100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]);
         } else {
             $arOneItem["DISCOUNT_PRICE_PERCENT"] = 0;
         }
         $arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION) . "%";
         $DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"];
     }
     unset($arOneItem);
     $arResult["ITEMS"]["AnDelCanBuy"] = $arOrder["BASKET_ITEMS"];
     // fill grid data (for new templates with custom columns)
     foreach ($arResult["ITEMS"] as $type => $arItems) {
         foreach ($arItems as $k => $arItem) {
             $arResult["GRID"]["ROWS"][$arItem["ID"]] = $arItem;
         }
     }
     $arResult["allSum"] = $allSum;
     $arResult["allWeight"] = $allWeight;
     $arResult["allWeight_FORMATED"] = roundEx(doubleval($allWeight / $this->weightKoef), SALE_WEIGHT_PRECISION) . " " . $this->weightUnit;
     $arResult["allSum_FORMATED"] = $this->getSaleFormatCurrency($allSum, $allCurrency);
     $arResult["DISCOUNT_PRICE_FORMATED"] = $this->getSaleFormatCurrency($arResult["DISCOUNT_PRICE"], $allCurrency);
     $arResult["PRICE_WITHOUT_DISCOUNT"] = $this->getSaleFormatCurrency($allSum + $DISCOUNT_PRICE_ALL, $allCurrency);
     if ($this->priceVatShowValue == 'Y') {
         $arResult["allVATSum"] = $allVATSum;
         $arResult["allVATSum_FORMATED"] = $this->getSaleFormatCurrency($allVATSum, $allCurrency);
         $arResult["allSum_wVAT_FORMATED"] = $this->getSaleFormatCurrency(doubleval($arResult["allSum"] - $allVATSum), $allCurrency);
     }
     if (!empty($arCoupons)) {
         $arResult["COUPON"] = htmlspecialcharsbx($arCoupons[0]);
     }
     if (count($arBasketItems) <= 0) {
         $arResult["ERROR_MESSAGE"] = GetMessage("SALE_EMPTY_BASKET");
     }
     $arResult["DISCOUNT_PRICE_ALL"] = $DISCOUNT_PRICE_ALL;
     $arResult["DISCOUNT_PRICE_ALL_FORMATED"] = $this->getSaleFormatCurrency($DISCOUNT_PRICE_ALL, $allCurrency);
     return $arResult;
 }
Exemple #8
0
	public function getBasketItems()
	{
		global $APPLICATION;
		$bUseCatalog = CModule::IncludeModule("catalog");
		$bUseIblock = $bUseCatalog;

		CSaleBasket::UpdateBasketPrices(CSaleBasket::GetBasketUserID(), SITE_ID);

		$bShowReady = False;
		$bShowDelay = False;
		$bShowSubscribe = False;
		$bShowNotAvail = False;
		$allSum = 0;
		$allWeight = 0;
		$allCurrency = CSaleLang::GetLangCurrency(SITE_ID);
		$allVATSum = 0;
		$arParents = array();

		$arResult["ITEMS"]["AnDelCanBuy"] = array();
		$arResult["ITEMS"]["DelDelCanBuy"] = array();
		$arResult["ITEMS"]["nAnCanBuy"] = array();
		$arResult["ITEMS"]["ProdSubscribe"] = array();
		$DISCOUNT_PRICE_ALL = 0;

		// BASKET PRODUCTS (including measures, ratio, iblock properties data)

		$arImgFields = array("PREVIEW_PICTURE", "DETAIL_PICTURE");
		$arBasketItems = array();
		$arSku2Parent = array();
		$arSetParentWeight = array();
		$dbItems = CSaleBasket::GetList(
			array("ID" => "ASC"),
			array(
				"FUSER_ID" => CSaleBasket::GetBasketUserID(),
				"LID" => SITE_ID,
				"ORDER_ID" => "NULL"
			),
			false,
			false,
			array(
				"ID", "NAME", "CALLBACK_FUNC", "MODULE", "PRODUCT_ID", "QUANTITY", "DELAY", "CAN_BUY",
				"PRICE", "WEIGHT", "DETAIL_PAGE_URL", "NOTES", "CURRENCY", "VAT_RATE", "CATALOG_XML_ID",
				"PRODUCT_XML_ID", "SUBSCRIBE", "DISCOUNT_PRICE", "PRODUCT_PROVIDER_CLASS", "TYPE", "SET_PARENT_ID"
			)
		);
		while ($arItem = $dbItems->GetNext())
		{
			$arBasketItems[] = $arItem;

			if (CSaleBasketHelper::isSetItem($arItem))
				continue;

			$arElementId[] = $arItem["PRODUCT_ID"];

			if ($bUseCatalog)
			{
				$arParent = CCatalogSku::GetProductInfo($arItem["PRODUCT_ID"]);

				if ($arParent)
				{
					$arElementId[] = $arParent["ID"];
					$arSku2Parent[$arItem["PRODUCT_ID"]] = $arParent["ID"];

					$arParents[$arItem["PRODUCT_ID"]]["PRODUCT_ID"] = $arParent["ID"];
					$arParents[$arItem["PRODUCT_ID"]]["IBLOCK_ID"] = $arParent["IBLOCK_ID"];
				}
			}
		}

		// get measures, ratio, sku props data and available quantity
		if (!empty($arBasketItems) && $bUseCatalog)
		{
			$arBasketItems = getMeasures($arBasketItems);
			$arBasketItems = getRatio($arBasketItems);
			$arBasketItems = $this->getAvailableQuantity($arBasketItems);
		}

		// get product properties data
		$arProductData = getProductProps($arElementId, array_merge(array("ID"), $arImgFields, $this->arCustomSelectFields));

		foreach ($arBasketItems as &$arItem)
		{

			$quantityIsFloat = false;
			if (number_format(doubleval($arItem['QUANTITY']), 2, '.', '') != intval($arItem['QUANTITY']))
			{
				$quantityIsFloat = true;
			}

			$arItem["QUANTITY"] = ($quantityIsFloat === false && $this->quantityFloat != "Y") ? intval($arItem['QUANTITY']) : number_format(doubleval($arItem['QUANTITY']), 2, '.', '');

			$arItem["PROPS"] = array();

			$dbProp = CSaleBasket::GetPropsList(
				array("SORT" => "ASC", "ID" => "ASC"),
				array("BASKET_ID" => $arItem["ID"], "!CODE" => array("CATALOG.XML_ID", "PRODUCT.XML_ID"))
			);
			while ($arProp = $dbProp->GetNext())
				$arItem["PROPS"][] = $arProp;

			$arItem["PRICE_VAT_VALUE"] = (($arItem["PRICE"] / ($arItem["VAT_RATE"] +1)) * $arItem["VAT_RATE"]);
			$arItem["PRICE_FORMATED"] = SaleFormatCurrency($arItem["PRICE"], $arItem["CURRENCY"]);

			$arItem["WEIGHT"] = doubleval($arItem["WEIGHT"]);
			$arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION)." ".$this->weightUnit;

			if (CSaleBasketHelper::isSetItem($arItem))
				$arSetParentWeight[$arItem["SET_PARENT_ID"]] += $arItem["WEIGHT"] * $arItem["QUANTITY"];

			if (array_key_exists($arItem["PRODUCT_ID"], $arProductData) && is_array($arProductData[$arItem["PRODUCT_ID"]]))
			{
				foreach ($arProductData[$arItem["PRODUCT_ID"]] as $key => $value)
				{
					if (strpos($key, "PROPERTY_") !== false || in_array($key, $arImgFields))
						$arItem[$key] = $value;
				}
			}

			if (array_key_exists($arItem["PRODUCT_ID"], $arSku2Parent)) // if sku element doesn't have value of some property - we'll show parent element value instead
			{
				$arFieldsToFill = array_merge($this->arCustomSelectFields, $arImgFields); // fields to be filled with parents' values if empty
				foreach ($arFieldsToFill as $field)
				{
					$fieldVal = (in_array($field, $arImgFields)) ? $field : $field."_VALUE";
					$parentId = $arSku2Parent[$arItem["PRODUCT_ID"]];

					if ((!isset($arItem[$fieldVal]) || (isset($arItem[$fieldVal]) && strlen($arItem[$fieldVal]) == 0))
						&& (isset($arProductData[$parentId][$fieldVal]) && !empty($arProductData[$parentId][$fieldVal]))) // can be array or string
					{
						$arItem[$fieldVal] = $arProductData[$parentId][$fieldVal];
					}
				}
			}

			foreach ($arItem as $key => $value) // format properties' values
			{
				if ((strpos($key, "PROPERTY_", 0) === 0) && (strrpos($key, "_VALUE") == strlen($key) - 6))
				{
					$code = str_replace(array("PROPERTY_", "_VALUE"), "", $key);
					$propData = $this->arIblockProps[$code];
					$arItem[$key] = CSaleHelper::getIblockPropInfo($value, $propData);
				}
			}

			$arItem["PREVIEW_PICTURE_SRC"] = "";
			if (isset($arItem["PREVIEW_PICTURE"]) && intval($arItem["PREVIEW_PICTURE"]) > 0)
			{
				$arImage = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]);
				if ($arImage)
				{
					$arFileTmp = CFile::ResizeImageGet(
						$arImage,
						array("width" => "110", "height" =>"110"),
						BX_RESIZE_IMAGE_PROPORTIONAL,
						true
					);

					$arItem["PREVIEW_PICTURE_SRC"] = $arFileTmp["src"];
				}
			}

			$arItem["DETAIL_PICTURE_SRC"] = "";
			if (isset($arItem["DETAIL_PICTURE"]) && intval($arItem["DETAIL_PICTURE"]) > 0)
			{
				$arImage = CFile::GetFileArray($arItem["DETAIL_PICTURE"]);
				if ($arImage)
				{
					$arFileTmp = CFile::ResizeImageGet(
						$arImage,
						array("width" => "110", "height" =>"110"),
						BX_RESIZE_IMAGE_PROPORTIONAL,
						true
					);

					$arItem["DETAIL_PICTURE_SRC"] = $arFileTmp["src"];
				}
			}
		}
		unset($arItem);

		// get sku props data
		if (!empty($arBasketItems) && $bUseCatalog && isset($this->offersProps) && !empty($this->offersProps))
		{
			$arBasketItems = $this->getSkuPropsData($arBasketItems, $arParents, $this->offersProps);
		}

		// count weight for set parent products
		foreach ($arBasketItems as &$arItem)
		{
			if (CSaleBasketHelper::isSetParent($arItem))
			{
				$arItem["WEIGHT"] = $arSetParentWeight[$arItem["ID"]] / $arItem["QUANTITY"];
				$arItem["WEIGHT_FORMATED"] = roundEx(doubleval($arItem["WEIGHT"] / $this->weightKoef), SALE_WEIGHT_PRECISION)." ".$this->weightUnit;
			}
		}

		if (isset($arItem))
		{
			unset($arItem);
		}
		// fill item arrays for old templates
		foreach ($arBasketItems as &$arItem)
		{
			if (CSaleBasketHelper::isSetItem($arItem))
				continue;

			if ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "N")
			{
				$allSum += ($arItem["PRICE"] * $arItem["QUANTITY"]);
				$allWeight += ($arItem["WEIGHT"] * $arItem["QUANTITY"]);
				$allVATSum += roundEx($arItem["PRICE_VAT_VALUE"] * $arItem["QUANTITY"], SALE_VALUE_PRECISION);

				$bShowReady = True;
				if(doubleval($arItem["DISCOUNT_PRICE"]) > 0)
				{
					if (0 < doubleval($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"]))
					{
						$arItem["DISCOUNT_PRICE_PERCENT"] = $arItem["DISCOUNT_PRICE"]*100 / ($arItem["DISCOUNT_PRICE"] + $arItem["PRICE"]);
					}
					else
					{
						$arItem["DISCOUNT_PRICE_PERCENT"] = 0;
					}
					$arItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION)."%";
					$DISCOUNT_PRICE_ALL += $arItem["DISCOUNT_PRICE"] * $arItem["QUANTITY"];
				}

				$arResult["ITEMS"]["AnDelCanBuy"][] = $arItem;
			}
			elseif ($arItem["CAN_BUY"] == "Y" && $arItem["DELAY"] == "Y")
			{
				$bShowDelay = True;

				$arResult["ITEMS"]["DelDelCanBuy"][] = $arItem;
			}
			elseif ($arItem["CAN_BUY"] == "N" && $arItem["SUBSCRIBE"] == "Y")
			{
				$bShowSubscribe = True;

				$arResult["ITEMS"]["ProdSubscribe"][] = $arItem;
			}
			else
			{
				$bShowNotAvail = True;
				$arItem["NOT_AVAILABLE"] = true;

				$arResult["ITEMS"]["nAnCanBuy"][] = $arItem;
			}
		}
		unset($arItem);

		$arResult["ShowReady"] = (($bShowReady)?"Y":"N");
		$arResult["ShowDelay"] = (($bShowDelay)?"Y":"N");
		$arResult["ShowNotAvail"] = (($bShowNotAvail)?"Y":"N");
		$arResult["ShowSubscribe"] = (($bShowSubscribe)?"Y":"N");

		$arOrder = array(
			'SITE_ID' => SITE_ID,
			'USER_ID' => $GLOBALS["USER"]->GetID(),
			'ORDER_PRICE' => $allSum,
			'ORDER_WEIGHT' => $allWeight,
			'BASKET_ITEMS' => $arResult["ITEMS"]["AnDelCanBuy"]
		);

		$arOptions = array(
			'COUNT_DISCOUNT_4_ALL_QUANTITY' => $this->countDiscount4AllQuantity,
		);

		$arErrors = array();

		CSaleDiscount::DoProcessOrder($arOrder, $arOptions, $arErrors);

		$allSum = 0;
		$allWeight = 0;
		$allVATSum = 0;

		$DISCOUNT_PRICE_ALL = 0;
		$priceWithoutDiscount = 0;

		foreach ($arOrder["BASKET_ITEMS"] as &$arOneItem)
		{
			$allWeight += ($arOneItem["WEIGHT"] * $arOneItem["QUANTITY"]);
			$allSum += ($arOneItem["PRICE"] * $arOneItem["QUANTITY"]);

			if (array_key_exists('VAT_VALUE', $arOneItem))
				$arOneItem["PRICE_VAT_VALUE"] = $arOneItem["VAT_VALUE"];
			$allVATSum += roundEx($arOneItem["PRICE_VAT_VALUE"] * $arOneItem["QUANTITY"], SALE_VALUE_PRECISION);
			$arOneItem["PRICE_FORMATED"] = SaleFormatCurrency($arOneItem["PRICE"], $arOneItem["CURRENCY"]);

			$arOneItem["FULL_PRICE"] = $arOneItem["PRICE"] + $arOneItem["DISCOUNT_PRICE"];
			$arOneItem["FULL_PRICE_FORMATED"] = SaleFormatCurrency($arOneItem["FULL_PRICE"], $arOneItem["CURRENCY"]);

			$arOneItem["SUM"] = SaleFormatCurrency($arOneItem["PRICE"] * $arOneItem["QUANTITY"], $arOneItem["CURRENCY"]);

			if (0 < doubleval($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]))
			{
				$arOneItem["DISCOUNT_PRICE_PERCENT"] = $arOneItem["DISCOUNT_PRICE"]*100 / ($arOneItem["DISCOUNT_PRICE"] + $arOneItem["PRICE"]);
			}
			else
			{
				$arOneItem["DISCOUNT_PRICE_PERCENT"] = 0;
			}
			$arOneItem["DISCOUNT_PRICE_PERCENT_FORMATED"] = roundEx($arOneItem["DISCOUNT_PRICE_PERCENT"], SALE_VALUE_PRECISION)."%";
			$DISCOUNT_PRICE_ALL += $arOneItem["DISCOUNT_PRICE"] * $arOneItem["QUANTITY"];
		}
		unset($arOneItem);

		$arResult["ITEMS"]["AnDelCanBuy"] = $arOrder["BASKET_ITEMS"];

		// fill grid data (for new templates with custom columns)
		foreach ($arResult["ITEMS"] as $type => $arItems)
		{
			foreach ($arItems as $k => $arItem)
			{
				$arResult["GRID"]["ROWS"][$arItem["ID"]] = $arItem;
			}
		}

		$arResult["allSum"] = $allSum;
		$arResult["allWeight"] = $allWeight;
		$arResult["allWeight_FORMATED"] = roundEx(doubleval($allWeight/$this->weightKoef), SALE_WEIGHT_PRECISION)." ".$this->weightUnit;
		$arResult["allSum_FORMATED"] = SaleFormatCurrency($allSum, $allCurrency);
		$arResult["DISCOUNT_PRICE_FORMATED"] = SaleFormatCurrency($arResult["DISCOUNT_PRICE"], $allCurrency);
		$arResult["PRICE_WITHOUT_DISCOUNT"] = SaleFormatCurrency($allSum + $DISCOUNT_PRICE_ALL, $allCurrency);

		if ($this->priceVatShowValue == 'Y')
		{
			$arResult["allVATSum"] = $allVATSum;
			$arResult["allVATSum_FORMATED"] = SaleFormatCurrency($allVATSum, $allCurrency);
			$arResult["allSum_wVAT_FORMATED"] = SaleFormatCurrency(doubleval($arResult["allSum"]-$allVATSum), $allCurrency);
		}

		if ($this->hideCoupon != "Y")
			$arCoupons = CCatalogDiscountCoupon::GetCoupons();

		if (!empty($arCoupons))
			$arResult["COUPON"] = htmlspecialcharsbx($arCoupons[0]);
		if(count($arBasketItems)<=0)
			$arResult["ERROR_MESSAGE"] = GetMessage("SALE_EMPTY_BASKET");

		$arResult["DISCOUNT_PRICE_ALL"] = $DISCOUNT_PRICE_ALL;
		$arResult["DISCOUNT_PRICE_ALL_FORMATED"] = SaleFormatCurrency($DISCOUNT_PRICE_ALL, $allCurrency);

		if($this->usePrepayment == "Y")
		{
			if(doubleval($arResult["allSum"]) > 0)
			{
				$personType = array();
				$dbPersonType = CSalePersonType::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("LID" => SITE_ID, "ACTIVE" => "Y"));
				while($arPersonType = $dbPersonType->Fetch())
				{
					$personType[] = $arPersonType["ID"];
				}

				if(!empty($personType))
				{
					$dbPaySysAction = CSalePaySystemAction::GetList(
							array(),
							array(
									"PS_ACTIVE" => "Y",
									"HAVE_PREPAY" => "Y",
									"PERSON_TYPE_ID" => $personType,
								),
							false,
							false,
							array("ID", "PAY_SYSTEM_ID", "PERSON_TYPE_ID", "NAME", "ACTION_FILE", "RESULT_FILE", "NEW_WINDOW", "PARAMS", "ENCODING", "LOGOTIP")
						);
					if ($arPaySysAction = $dbPaySysAction->Fetch())
					{
						CSalePaySystemAction::InitParamarrays(false, false, $arPaySysAction["PARAMS"]);

						$pathToAction = $_SERVER["DOCUMENT_ROOT"].$arPaySysAction["ACTION_FILE"];

						$pathToAction = str_replace("\\", "/", $pathToAction);
						while (substr($pathToAction, strlen($pathToAction) - 1, 1) == "/")
							$pathToAction = substr($pathToAction, 0, strlen($pathToAction) - 1);

						if (file_exists($pathToAction))
						{
							if (is_dir($pathToAction) && file_exists($pathToAction."/pre_payment.php"))
								$pathToAction .= "/pre_payment.php";

							include_once($pathToAction);
							$psPreAction = new CSalePaySystemPrePayment;

							if($psPreAction->init())
							{
								$orderData = array(
										"PATH_TO_ORDER" => $this->pathToOrder,
										"AMOUNT" => $arResult["allSum"],
										"BASKET_ITEMS" => $arResult["ITEMS"]["AnDelCanBuy"],
									);
								if(!$psPreAction->BasketButtonAction($orderData))
								{
									if($e = $APPLICATION->GetException())
										$arResult["WARNING_MESSAGE"][] = $e->GetString();
								}

								$arResult["PREPAY_BUTTON"] = $psPreAction->BasketButtonShow();
							}
						}
					}
				}
			}
		}

		return $arResult;
	}