{ $img = CFile::GetFileArray($viewed[$fields['ID']]['DETAIL_PICTURE']); if($img) $viewed[$fields['ID']]['DETAIL_PICTURE'] = $img['SRC']; else $viewed[$fields['ID']]['DETAIL_PICTURE'] = false; } else { $viewed[$fields['ID']]['DETAIL_PICTURE'] = false; } } // Prices $priceIterator = CPrice::getList(array(), array("PRODUCT_ID" => $filter['ID']), false, false, array("PRODUCT_ID", "PRICE", "CURRENCY")); while($price = $priceIterator->fetch()) { if(!isset($viewed[$price['PRODUCT_ID']]['PRICE'])) { $viewed[$price['PRODUCT_ID']]['PRICE'] = $price['PRICE']; $viewed[$price['PRODUCT_ID']]['CURRENCY'] = $price['CURRENCY']; } } } // $arViewedResult = fDeleteDoubleProduct($viewed, $arFilterRecommended, 'N'); if (empty($arViewedResult["ITEMS"])) $displayNoneViewed = "none"; $tabBasket = "tabs";
protected function getSkuPrices() { $result = array(); if ($this->offers) { $ids = array(); foreach ($this->offers as $id => $offers) { foreach ($offers as $offer) { $ids[] = $offer['ID']; } } if ($ids) { $priceIds = $this->getVisiblePrices(); foreach ($priceIds as $id) { $dbPrice = \CPrice::getList(array(), array('PRODUCT_ID' => $ids, 'CATALOG_GROUP_ID' => $id), false, false, array('PRODUCT_ID', 'PRICE', 'CURRENCY')); while ($arPrice = $dbPrice->fetch()) { $result[$id][$arPrice["PRODUCT_ID"]] = array('PRICE' => $arPrice['PRICE'], 'CURRENCY' => $arPrice['CURRENCY']); } } } } return $result; }
$row =& $lAdmin->AddRow($arItems["ID"], $arItems); $isProductExistSKU = false; if (!$boolSubscribe) { $isProductExistSKU = $arCatalogProduct['EXIST_SKU']; } $arResult = array(); if ($isProductExistSKU) { $arResult = GetProductSku($buyerId, $lid, $arItems["ID"], $arItems["NAME"], '', $arItems); $arSKUId = $arSKUPricesResult = array(); if (isset($arResult["SKU_ELEMENTS"]) && !empty($arResult["SKU_ELEMENTS"]) && is_array($arResult["SKU_ELEMENTS"])) { foreach ($arResult["SKU_ELEMENTS"] as $sku) { $arSKUId[] = $sku["ID"]; } } foreach ($arPrices as $price) { $dbPrice = CPrice::getList(array(), array('PRODUCT_ID' => $arSKUId, 'CATALOG_GROUP_ID' => $price['ID']), false, false, array('PRODUCT_ID', 'PRICE')); while ($arPrice = $dbPrice->fetch()) { $arSKUPricesResult[$price['ID']][$arPrice["PRODUCT_ID"]] = $arPrice["PRICE"]; } } $active = $arItems["ACTIVE"] == 'Y' ? GetMEssage('SPS_PRODUCT_ACTIVE') : GetMEssage('SPS_PRODUCT_NO_ACTIVE'); if (!empty($arResult["SKU_ELEMENTS"])) { $OfferIblockId = $arResult["OFFERS_IBLOCK_ID"]; $row->AddField("ACTIVE", $active); $row->AddField("ACT", '<input type="button" onclick="fShowSku(this, ' . CUtil::PhpToJSObject($arResult["SKU_ELEMENTS"]) . ');" name="btn_show_sku_' . $arItems["ID"] . '" value="' . GetMessage("SPS_SKU_SHOW") . '">'); $row->AddViewField("PREVIEW_PICTURE", CFileInput::Show('NO_FIELDS[' . $arItems['ID'] . '][PREVIEW_PICTURE]', $arItems['PREVIEW_PICTURE'], array("IMAGE" => "Y", "PATH" => "Y", "FILE_SIZE" => "Y", "DIMENSIONS" => "Y", "IMAGE_POPUP" => "Y", "MAX_SIZE" => $maxImageSize, "MIN_SIZE" => $minImageSize), array('upload' => false, 'medialib' => false, 'file_dialog' => false, 'cloud' => false, 'del' => false, 'description' => false))); $row->AddViewField("DETAIL_PICTURE", CFileInput::Show('NO_FIELDS[' . $arItems['ID'] . '][DETAIL_PICTURE]', $arItems['DETAIL_PICTURE'], array("IMAGE" => "Y", "PATH" => "Y", "FILE_SIZE" => "Y", "DIMENSIONS" => "Y", "IMAGE_POPUP" => "Y", "MAX_SIZE" => $maxImageSize, "MIN_SIZE" => $minImageSize), array('upload' => false, 'medialib' => false, 'file_dialog' => false, 'cloud' => false, 'del' => false, 'description' => false))); $arProperties = array(); if (!empty($arSelectedProps)) { $rsProperties = CIBlockElement::GetProperty($iblockId, $arItems["ID"]); while ($ar = $rsProperties->Fetch()) {
)); while($viewed = $viewedIterator->fetch()) { $viewed['MODULE'] = 'catalog'; $arViewed[$viewedCount] = $viewed; $arViewedIds[] = $viewed['PRODUCT_ID']; $mapViewed[$viewed['PRODUCT_ID']] = $viewedCount; $viewedCount++; } unset($viewedCount); $baseGroup = CCatalogGroup::getBaseGroup(); if (!empty($arViewedIds)) { $priceIterator = CPrice::getList( array(), array("PRODUCT_ID" => $arViewedIds, 'CATALOG_GROUP_ID' => $baseGroup['ID']), false, false, array("PRODUCT_ID", "PRICE", "CURRENCY")); while($productPrice = $priceIterator->fetch() ) { if (isset($mapViewed[$productPrice['PRODUCT_ID']])) { $key = $mapViewed[$productPrice['PRODUCT_ID']]; $arViewed[$key]["PRICE"] = $productPrice["PRICE"]; $arViewed[$key]["CURRENCY"] = $productPrice["CURRENCY"]; } } } $viewedCnt = count($arViewed); $arViewed = array_slice($arViewed, 0, 2); if (count($arViewed) <= 0) $displayNoneViewed = "none";
/** * The function select viewed product * * @param array $arOrder - array to sort * @param array $arFilter - array to filter * @param array $arGroupBy - array to group records * @param array $arNavStartParams - array to parameters * @param array $arSelectFields - array to selectes fields * @return object $dbRes - object result */ public static function GetList($arOrder = array("ID" => "DESC"), $arFilter = array(), $arGroupBy = false, $arNavStartParams = false, $arSelectFields = array()) { global $DB; if (array_key_exists("DATE_FROM", $arFilter)) { $arFilter[">=DATE_VISIT"] = trim($arFilter["DATE_FROM"]); unset($arFilter["DATE_FROM"]); } if (array_key_exists("DATE_TO", $arFilter)) { $arFilter["<=DATE_VISIT"] = trim($arFilter["DATE_TO"]); unset($arFilter["DATE_TO"]); } if (!$arSelectFields || count($arSelectFields) <= 0 || in_array("*", $arSelectFields)) { $arSelectFields = array("ID", "FUSER_ID", "DATE_VISIT", "PRODUCT_ID", "MODULE", "LID", "NAME", "DETAIL_PAGE_URL", "CURRENCY", "PRICE", "NOTES", "PREVIEW_PICTURE", "DETAIL_PICTURE", "CALLBACK_FUNC", "PRODUCT_PROVIDER_CLASS"); } if (\Bitrix\Main\Loader::includeModule("catalog")) { if (\Bitrix\Main\Config\Option::get("sale", "viewed_capability", "") == "Y") { foreach ($arFilter as $key => $value) { if ($key == "LID") { $arFilter['SITE_ID'] = $value; unset($arFilter['LID']); } } $limit = 100; if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) >= 0) { $limit = IntVal($arNavStartParams["nTopCount"]); } $viewedIterator = \Bitrix\Catalog\CatalogViewedProductTable::getList(array("filter" => $arFilter, "select" => array("ID", "PRODUCT_ID", "DATE_VISIT", "LID" => "SITE_ID", "NAME" => "ELEMENT.NAME"), "order" => array("DATE_VISIT" => "DESC"), "limit" => $limit)); $viewed = array(); while ($row = $viewedIterator->fetch()) { $row['MODULE'] = "catalog"; $row['DATE_VISIT'] = $row['DATE_VISIT']->toString(); $viewed[$row['PRODUCT_ID']] = $row; } if (count($viewed)) { // Map to parent sku $newIds = array(); $ids = array_keys($viewed); $catalogIterator = CCatalog::getList(); while ($catalog = $catalogIterator->fetch()) { if ($catalog['IBLOCK_TYPE_ID'] == "offers") { $elementIterator = CIBlockElement::getList(array(), array("ID" => $ids, "IBLOCK_ID" => $catalog['IBLOCK_ID']), false, false, array("ID", "IBLOCK_ID", "PROPERTY_" . $catalog['SKU_PROPERTY_ID'])); while ($item = $elementIterator->fetch()) { $propertyName = "PROPERTY_" . $catalog['SKU_PROPERTY_ID'] . "_VALUE"; $parentId = $item[$propertyName]; if (!empty($parentId)) { $newIds[$item['ID']] = $parentId; } else { $newIds[$item['ID']] = $item['ID']; } } } } // Push missing foreach ($ids as $id) { if (!isset($newIds[$id])) { $newIds[$id] = $id; } } $filter = array("ID" => array_values($newIds)); if (!count($filter['ID'])) { $filter = array("ID" => -1); } $mapped = array(); if (in_array("DETAIL_PAGE_URL", $arSelectFields) || in_array("PREVIEW_PICTURE", $arSelectFields) || in_array("DETAIL_PICTURE", $arSelectFields)) { $elementIterator = CIBlockElement::GetList(array(), $filter); while ($elementObj = $elementIterator->GetNextElement()) { $fields = $elementObj->GetFields(); $mapped[$fields['ID']]['PREVIEW_PICTURE'] = $fields['PREVIEW_PICTURE']; $mapped[$fields['ID']]['DETAIL_PICTURE'] = $fields['DETAIL_PICTURE']; } } foreach ($newIds as $natural => $tr) { $viewed[$natural]['PREVIEW_PICTURE'] = $mapped[$tr]['DETAIL_PICTURE']; $viewed[$natural]['DETAIL_PICTURE'] = $mapped[$tr]['PREVIEW_PICTURE']; $viewed[$natural]['PRODUCT_ID'] = $tr; } if (in_array("CURRENCY", $arSelectFields) || in_array("PRICE", $arSelectFields)) { // Prices $priceIterator = CPrice::getList(array(), array("PRODUCT_ID" => $ids), false, false, array("PRODUCT_ID", "PRICE", "CURRENCY")); while ($price = $priceIterator->fetch()) { if (!isset($viewed[$price['PRODUCT_ID']]['PRICE'])) { $viewed[$price['PRODUCT_ID']]['PRICE'] = $price['PRICE']; $viewed[$price['PRODUCT_ID']]['CURRENCY'] = $price['CURRENCY']; } } } } // resort $dbresult = new CDBResult(); $dbresult->InitFromArray(array_values($viewed)); return $dbresult; } } $arFields = array("ID" => array("FIELD" => "V.ID", "TYPE" => "int"), "FUSER_ID" => array("FIELD" => "V.FUSER_ID", "TYPE" => "int"), "DATE_VISIT" => array("FIELD" => "V.DATE_VISIT", "TYPE" => "datetime"), "PRODUCT_ID" => array("FIELD" => "V.PRODUCT_ID", "TYPE" => "int"), "MODULE" => array("FIELD" => "V.MODULE", "TYPE" => "string"), "LID" => array("FIELD" => "V.LID", "TYPE" => "string"), "NAME" => array("FIELD" => "V.NAME", "TYPE" => "string"), "DETAIL_PAGE_URL" => array("FIELD" => "V.DETAIL_PAGE_URL", "TYPE" => "string"), "CURRENCY" => array("FIELD" => "V.CURRENCY", "TYPE" => "string"), "PRICE" => array("FIELD" => "V.PRICE", "TYPE" => "double"), "NOTES" => array("FIELD" => "V.NOTES", "TYPE" => "string"), "PREVIEW_PICTURE" => array("FIELD" => "V.PREVIEW_PICTURE", "TYPE" => "string"), "DETAIL_PICTURE" => array("FIELD" => "V.DETAIL_PICTURE", "TYPE" => "string"), "CALLBACK_FUNC" => array("FIELD" => "V.CALLBACK_FUNC", "TYPE" => "string"), "PRODUCT_PROVIDER_CLASS" => array("FIELD" => "V.PRODUCT_PROVIDER_CLASS", "TYPE" => "string")); $arSqls = CSaleOrder::PrepareSql($arFields, $arOrder, $arFilter, $arGroupBy, $arSelectFields); $arSqls["SELECT"] = str_replace("%%_DISTINCT_%%", "", $arSqls["SELECT"]); $strSql = "SELECT " . $arSqls["SELECT"] . " " . "FROM b_sale_viewed_product V "; if (strlen($arSqls["WHERE"]) > 0) { $strSql .= "WHERE " . $arSqls["WHERE"] . " "; } if (strlen($arSqls["GROUPBY"]) > 0) { $strSql .= "GROUP BY " . $arSqls["GROUPBY"] . " "; } if (strlen($arSqls["ORDERBY"]) > 0) { $strSql .= "ORDER BY " . $arSqls["ORDERBY"] . " "; } if (is_array($arGroupBy) && count($arGroupBy) == 0) { $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); if ($arRes = $dbRes->Fetch()) { return $arRes["CNT"]; } else { return false; } } if (is_array($arNavStartParams) && IntVal($arNavStartParams["nTopCount"]) <= 0) { $strSql_tmp = "SELECT COUNT('x') as CNT " . "FROM b_sale_viewed_product B "; if (strlen($arSqls["WHERE"]) > 0) { $strSql_tmp .= "WHERE " . $arSqls["WHERE"] . " "; } if (strlen($arSqls["GROUPBY"]) > 0) { $strSql_tmp .= "GROUP BY " . $arSqls["GROUPBY"] . " "; } $dbRes = $DB->Query($strSql_tmp, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $cnt = 0; if (strlen($arSqls["GROUPBY"]) <= 0) { if ($arRes = $dbRes->Fetch()) { $cnt = $arRes["CNT"]; } } else { $cnt = $dbRes->SelectedRowsCount(); } $dbRes = new CDBResult(); $dbRes->NavQuery($strSql, $cnt, $arNavStartParams); } else { $strSql = $DB->TopSql($strSql, $arNavStartParams["nTopCount"]); $dbRes = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } return $dbRes; }