Exemple #1
0
	if ($pid === "")
		unset($arParams["OFFERS_CART_PROPERTIES"][$i]);

if($this->StartResultCache(false, array($elementID, ($arParams["CACHE_GROUPS"]==="N"? false: $USER->GetGroups()))))
{
	if(!CModule::IncludeModule("catalog"))
	{
		ShowError(GetMessage("CATALOG_MODULE_NOT_INSTALLED"));
		$this->AbortResultCache();
		return;
	}
	$isProductHaveSet = CCatalogProductSet::isProductHaveSet($elementID, CCatalogProductSet::TYPE_GROUP);
	$product = false;
	if (!$isProductHaveSet)
	{
		$product = CCatalogSKU::GetProductInfo($elementID, $arParams['IBLOCK_ID']);
		if (!empty($product))
		{
			$isProductHaveSet = true;
		}
	}
	if (!$isProductHaveSet)
	{
		$this->AbortResultCache();
		return;
	}

	if (!empty($product))
	{
		$arResult['PRODUCT_ID'] = $product['ID'];
		$arResult['PRODUCT_IBLOCK_ID'] = $product['IBLOCK_ID'];
Exemple #2
0
 protected function getFilter()
 {
     $arFilter = array("IBLOCK_ID" => $this->getIblockId(), 'SECTION_ID' => $this->getSectionId() > 0 ? $this->getSectionId() : 0, 'ACTIVE' => empty($_REQUEST['filter_active']) ? 'Y' : $_REQUEST['filter_active'], "WF_PARENT_ELEMENT_ID" => false, "SHOW_NEW" => "Y");
     if ($arProps = $this->getProps()) {
         $filtered = null;
         foreach ($arProps as $arProp) {
             $value = $_REQUEST['filter_el_property_' . $arProp["ID"]];
             if (array_key_exists("AddFilterFields", $arProp["PROPERTY_USER_TYPE"])) {
                 call_user_func_array($arProp["PROPERTY_USER_TYPE"]["AddFilterFields"], array($arProp, array("VALUE" => "filter_el_property_" . $arProp["ID"]), &$arFilter, &$filtered));
             } elseif (is_array($value) || strlen($value)) {
                 if ($value === "NOT_REF") {
                     $value = false;
                 }
                 $arFilter["?PROPERTY_" . $arProp["ID"]] = $value;
             }
         }
     }
     $arSubQuery = array();
     if ($arSKUProps = $this->getSkuProps()) {
         $arCatalog = $this->getOffersCatalog();
         $arSubQuery = array("IBLOCK_ID" => $arCatalog['IBLOCK_ID']);
         $filtered = null;
         for ($i = 0, $intPropCount = count($arSKUProps); $i < $intPropCount; $i++) {
             if ('Y' == $arSKUProps[$i]["FILTRABLE"] && 'F' != $arSKUProps[$i]["PROPERTY_TYPE"] && $arCatalog['SKU_PROPERTY_ID'] != $arSKUProps[$i]["ID"]) {
                 if (array_key_exists("AddFilterFields", $arSKUProps[$i]["PROPERTY_USER_TYPE"])) {
                     call_user_func_array($arSKUProps[$i]["PROPERTY_USER_TYPE"]["AddFilterFields"], array($arSKUProps[$i], array("VALUE" => "filter_sub_el_property_" . $arSKUProps[$i]["ID"]), &$arSubQuery, &$filtered));
                 } else {
                     $value = $_REQUEST['filter_sub_el_property_' . $arSKUProps[$i]["ID"]];
                     if (is_array($value) || strlen($value)) {
                         if ($value === "NOT_REF") {
                             $value = false;
                         }
                         $arSubQuery["?PROPERTY_" . $arSKUProps[$i]["ID"]] = $value;
                     }
                 }
             }
         }
     }
     if (!empty($_REQUEST["filter_timestamp_from"])) {
         $arFilter["DATE_MODIFY_FROM"] = $_REQUEST["filter_timestamp_from"];
     }
     if (!empty($_REQUEST["filter_timestamp_to"])) {
         $arFilter["DATE_MODIFY_TO"] = $_REQUEST["filter_timestamp_to"];
     }
     if (!empty($_REQUEST["filter_code"])) {
         $arFilter["CODE"] = $_REQUEST["filter_code"];
     }
     $arSearchedIds = $arSearchedSectionIds = null;
     if (!empty($_REQUEST['QUERY'])) {
         $arFilter['QUERY'] = $_REQUEST['QUERY'];
         $arSearchedIds = $arSearchedSectionIds = array(0);
         if (preg_match('#^[0-9\\s]+$#', $_REQUEST['QUERY'])) {
             $barcode = preg_replace('#[^0-9]#', '', $_REQUEST['QUERY']);
             if (strlen($barcode) > 0) {
                 $rsBarCode = \CCatalogStoreBarCode::getList(array(), array("BARCODE" => $barcode), false, false, array('PRODUCT_ID'));
                 while ($res = $rsBarCode->Fetch()) {
                     $res2 = \CCatalogSKU::GetProductInfo($res["PRODUCT_ID"]);
                     $arSearchedIds[] = $res2 ? $res2['ID'] : $res['PRODUCT_ID'];
                 }
             }
         } elseif ($this->isAdvancedSearchAvailable()) {
             $arFilter['PARAM2'] = $this->getIblockId();
             if (!empty($arFilter['SECTION_ID'])) {
                 $arFilter['PARAMS'] = array('iblock_section' => $arFilter['SECTION_ID']);
             }
             $obSearch = new \CSearch();
             $obSearch->Search($arFilter);
             $cnt = 0;
             $activeSectionId = $this->getSectionId();
             while ($ar = $obSearch->Fetch()) {
                 if (strpos($ar['ITEM_ID'], 'S') === 0) {
                     $sectionId = preg_replace('#[^0-9]+#', '', $ar['ITEM_ID']);
                     if ($sectionId != $activeSectionId) {
                         $arSearchedSectionIds[] = $sectionId;
                     }
                 } else {
                     $arSearchedIds[] = $ar['ITEM_ID'];
                 }
                 if (++$cnt >= 100) {
                     break;
                 }
             }
         } else {
             $arSearchedIds = $arSearchedSectionIds = null;
             $arFilter['NAME'] = $_REQUEST['QUERY'];
         }
     }
     if (sizeof($arSubQuery) > 1) {
         $arFilteredIds = array(0);
         $db = \CIBlockElement::GetList(array(), $arSubQuery, false, false, array('PROPERTY_' . $arCatalog['SKU_PROPERTY_ID']));
         while ($res = $db->Fetch()) {
             $arFilteredIds[] = $res['PROPERTY_' . $arCatalog['SKU_PROPERTY_ID'] . '_VALUE'];
         }
         $arFilter['ID'] = is_array($arSearchedIds) ? array_intersect($arFilteredIds, $arSearchedIds) : $arFilteredIds;
     } elseif ($arSearchedIds) {
         $arFilter['ID'] = $arSearchedIds;
     }
     if ($arSearchedSectionIds) {
         $arFilter['S_ID'] = $arSearchedSectionIds;
     }
     unset($arFilter['PARAM1'], $arFilter['PARAM2'], $arFilter['PARAMS']);
     if ($this->isFiltering() || !empty($_REQUEST['QUERY'])) {
         $arFilter['INCLUDE_SUBSECTIONS'] = 'Y';
         if (isset($arFilter['SECTION_ID']) && $arFilter['SECTION_ID'] == 0) {
             unset($arFilter["SECTION_ID"]);
         }
     }
     return $arFilter;
 }
 public function GetDiscount($intProductID, $intIBlockID, $arCatalogGroups = array(), $arUserGroups = array(), $strRenewal = "N", $siteID = false, $arDiscountCoupons = false, $boolSKU = true, $boolGetIDS = false)
 {
     global $DB;
     global $APPLICATION;
     global $stackCacheManager;
     foreach (GetModuleEvents("catalog", "OnGetDiscount", true) as $arEvent) {
         $mxResult = ExecuteModuleEventEx($arEvent, array($intProductID, $intIBlockID, $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, $boolSKU, $boolGetIDS));
         if (true !== $mxResult) {
             return $mxResult;
         }
     }
     $boolSKU = true === $boolSKU ? true : false;
     $boolGetIDS = true === $boolGetIDS ? true : false;
     $intProductID = intval($intProductID);
     if (0 >= $intProductID) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_PRODUCT_ID_ABSENT"), "NO_PRODUCT_ID");
         return false;
     }
     $intIBlockID = intval($intIBlockID);
     if (0 >= $intIBlockID) {
         $APPLICATION->ThrowException(GetMessage("BT_MOD_CATALOG_DISC_ERR_IBLOCK_ID_ABSENT"), "NO_IBLOCK_ID");
         return false;
     }
     if (isset($arCatalogGroups)) {
         if (is_array($arCatalogGroups)) {
             array_walk($arCatalogGroups, create_function("&\$item", "\$item=intval(\$item);"));
             $arCatalogGroups = array_unique($arCatalogGroups);
         } else {
             if (intval($arCatalogGroups) . "|" == $arCatalogGroups . "|") {
                 $arCatalogGroups = array(intval($arCatalogGroups));
             } else {
                 $arCatalogGroups = array();
             }
         }
     } else {
         $arCatalogGroups = array();
     }
     if (!is_array($arUserGroups) && intval($arUserGroups) . "|" == $arUserGroups . "|") {
         $arUserGroups = array(intval($arUserGroups));
     }
     if (!is_array($arUserGroups)) {
         $arUserGroups = array();
     }
     if (!in_array(2, $arUserGroups)) {
         $arUserGroups[] = 2;
     }
     $strRenewal = $strRenewal == "Y" ? "Y" : "N";
     if ($siteID === false) {
         $siteID = SITE_ID;
     }
     if ($arDiscountCoupons === false) {
         $arDiscountCoupons = CCatalogDiscountCoupon::GetCoupons();
     }
     $arSKU = false;
     if ($boolSKU) {
         $arSKU = CCatalogSKU::GetProductInfo($intProductID, $intIBlockID);
         if (!is_array($arSKU)) {
             $boolSKU = false;
         }
     }
     $arResult = array();
     $arResultID = array();
     $arFilter = array('PRICE_TYPE_ID' => $arCatalogGroups, 'USER_GROUP_ID' => $arUserGroups);
     $arDiscountIDs = CCatalogDiscount::__GetDiscountID($arFilter);
     if (!empty($arDiscountIDs)) {
         $boolGenerate = false;
         $arSelect = array("ID", "TYPE", "SITE_ID", "ACTIVE", "ACTIVE_FROM", "ACTIVE_TO", "RENEWAL", "NAME", "SORT", "MAX_DISCOUNT", "VALUE_TYPE", "VALUE", "CURRENCY", "PRIORITY", "LAST_DISCOUNT", "COUPON", "COUPON_ONE_TIME", "COUPON_ACTIVE", 'UNPACK');
         $strDate = date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL")));
         $arFilter = array("ID" => $arDiscountIDs, "SITE_ID" => $siteID, "TYPE" => DISCOUNT_TYPE_STANDART, "ACTIVE" => "Y", "RENEWAL" => $strRenewal, "+<=ACTIVE_FROM" => $strDate, "+>=ACTIVE_TO" => $strDate);
         if (is_array($arDiscountCoupons)) {
             $arFilter["+COUPON"] = $arDiscountCoupons;
         }
         $rsPriceDiscounts = CCatalogDiscount::GetList(array(), $arFilter, false, false, $arSelect);
         while ($arPriceDiscount = $rsPriceDiscounts->Fetch()) {
             if ($arPriceDiscount['COUPON_ACTIVE'] != 'N') {
                 if (!$boolGenerate) {
                     $arProduct = array('ID' => $intProductID, 'IBLOCK_ID' => $intIBlockID);
                     if (!self::__GenerateFields($arProduct)) {
                         return false;
                     }
                     $boolGenerate = true;
                 }
                 if (CCatalogDiscount::__Unpack($arProduct, $arPriceDiscount['UNPACK'])) {
                     unset($arPriceDiscount['UNPACK']);
                     $arResult[] = $arPriceDiscount;
                     $arResultID[] = $arPriceDiscount['ID'];
                 }
             }
         }
     }
     if ($boolSKU) {
         $arDiscountParent = CCatalogDiscount::GetDiscount($arSKU['ID'], $arSKU['IBLOCK_ID'], $arCatalogGroups, $arUserGroups, $strRenewal, $siteID, $arDiscountCoupons, false, false);
         if (!empty($arDiscountParent)) {
             if (empty($arResult)) {
                 $arResult = $arDiscountParent;
             } else {
                 foreach ($arDiscountParent as &$arOneParentDiscount) {
                     if (in_array($arOneParentDiscount['ID'], $arResultID)) {
                         continue;
                     }
                     $arResult[] = $arOneParentDiscount;
                     $arResultID[] = $arOneParentDiscount['ID'];
                 }
                 if (isset($arOneParentDiscount)) {
                     unset($arOneParentDiscount);
                 }
             }
         }
     }
     if (!$boolGetIDS) {
         $arDiscSave = CCatalogDiscountSave::GetDiscount(array('USER_ID' => 0, 'USER_GROUPS' => $arUserGroups, 'SITE_ID' => $siteID));
         if (!empty($arDiscSave)) {
             $arResult = !empty($arResult) ? array_merge($arResult, $arDiscSave) : $arDiscSave;
         }
     } else {
         $arResult = $arResultID;
     }
     foreach (GetModuleEvents("catalog", "OnGetDiscountResult", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$arResult));
     }
     return $arResult;
 }
Exemple #4
0
 protected static function getOrderInfo($orderId)
 {
     // order itself
     $order = \CSaleOrder::getById($orderId);
     // buyer info
     $siteUserId = $order['USER_ID'];
     $phone = '';
     $email = '';
     $result = \CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $orderId));
     while ($row = $result->fetch()) {
         if (empty($phone) && stripos($row['CODE'], 'PHONE') !== false) {
             $stPhone = static::normalizePhoneNumber($row['VALUE']);
             if (!empty($stPhone)) {
                 $phone = sha1($stPhone);
             }
         }
         if (empty($email) && stripos($row['CODE'], 'EMAIL') !== false) {
             if (!empty($row['VALUE'])) {
                 $email = sha1($row['VALUE']);
             }
         }
     }
     // products info
     $products = array();
     $result = \CSaleBasket::getList(array(), $arFilter = array('ORDER_ID' => $orderId, 'MODULE' => 'catalog'), false, false, array('PRODUCT_ID', 'RECOMMENDATION', 'QUANTITY', 'PRICE', 'CURRENCY'));
     while ($row = $result->fetch()) {
         $productInfo = \CCatalogSKU::GetProductInfo($row['PRODUCT_ID']);
         $iblockId = 0;
         if (!empty($productInfo['ID'])) {
             $realProductId = $productInfo['ID'];
             $iblockId = $productInfo['IBLOCK_ID'];
         } else {
             $realProductId = $row['PRODUCT_ID'];
             // get iblock id
             $element = \Bitrix\Iblock\ElementTable::getRow(array('select' => array('IBLOCK_ID'), 'filter' => array('=ID' => $realProductId)));
             if (!empty($element)) {
                 $iblockId = $element['IBLOCK_ID'];
             }
         }
         $products[] = array('product_id' => $realProductId, 'iblock_id' => $iblockId, 'quantity' => $row['QUANTITY'], 'price' => $row['PRICE'], 'currency' => $row['CURRENCY'], 'recommendation' => $row['RECOMMENDATION']);
     }
     // all together
     $data = array('order_id' => $orderId, 'user_id' => $siteUserId, 'phone' => $phone, 'email' => $email, 'products' => $products, 'price' => $order['PRICE'], 'currency' => $order['CURRENCY']);
     return $data;
 }
Exemple #5
0
 protected static function countSessionOrder($orderId)
 {
     if (Main\Loader::includeModule('sale') && Main\Loader::includeModule('catalog') && Main\Loader::includeModule('currency')) {
         $orderLinks = OrderTable::getList(array('filter' => array('=ORDER_ID' => $orderId, '=PROCESSED' => OrderTable::NOT_PROCESSED), 'select' => array('ID', 'BANNER_ID')));
         $orderLink = $orderLinks->fetch();
         if ($orderLink) {
             $linkedProductsList = static::getBannerLinkedProducts($orderLink['BANNER_ID']);
             if (count($linkedProductsList) > 0) {
                 $basket = BasketTable::getList(array('filter' => array('=ORDER_ID' => $orderId), 'select' => array('PRODUCT_ID', 'GROSS_PROFIT', 'SUMMARY_PRICE', 'SUMMARY_PURCHASING_PRICE', 'QUANTITY')));
                 $sum = 0;
                 while ($item = $basket->fetch()) {
                     if (in_array($item['PRODUCT_ID'], $linkedProductsList)) {
                         $sum += static::getProductProfit($item);
                     } else {
                         $productInfo = \CCatalogSKU::GetProductInfo($item['PRODUCT_ID']);
                         if (is_array($productInfo) && in_array($productInfo['ID'], $linkedProductsList)) {
                             $sum += static::getProductProfit($item);
                         }
                     }
                 }
                 OrderTable::update($orderLink['ID'], array('SUM' => $sum, 'PROCESSED' => OrderTable::PROCESSED));
             }
         }
     }
 }
 protected static function getOrderInfo($orderId)
 {
     // order itself
     $order = \CSaleOrder::getById($orderId);
     // buyer info
     $siteUserId = $order['USER_ID'];
     $phone = '';
     $email = '';
     $result = \CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $orderId));
     while ($row = $result->fetch()) {
         if (empty($phone) && stripos($row['CODE'], 'PHONE') !== false) {
             $stPhone = static::normalizePhoneNumber($row['VALUE']);
             if (!empty($stPhone)) {
                 $phone = sha1($stPhone);
             }
         }
         if (empty($email) && stripos($row['CODE'], 'EMAIL') !== false) {
             if (!empty($row['VALUE'])) {
                 $email = sha1($row['VALUE']);
             }
         }
     }
     // products info
     $products = array();
     $result = \CSaleBasket::getList(array(), $arFilter = array('ORDER_ID' => $orderId), false, false, array('PRODUCT_ID', 'RECOMMENDATION'));
     while ($row = $result->fetch()) {
         $productInfo = \CCatalogSKU::GetProductInfo($row['PRODUCT_ID']);
         if (!empty($productInfo['ID'])) {
             $realProductId = $productInfo['ID'];
         } else {
             $realProductId = $row['PRODUCT_ID'];
         }
         $products[] = array('product_id' => $realProductId, 'recommendation' => $row['RECOMMENDATION']);
     }
     // all together
     $data = array('order_id' => $orderId, 'user_id' => $siteUserId, 'phone' => $phone, 'email' => $email, 'products' => $products);
     return $data;
 }