当前位置: 首页>>代码示例>>PHP>>正文


PHP CCatalogSKU类代码示例

本文整理汇总了PHP中CCatalogSKU的典型用法代码示例。如果您正苦于以下问题:PHP CCatalogSKU类的具体用法?PHP CCatalogSKU怎么用?PHP CCatalogSKU使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CCatalogSKU类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getOfferObject

 public static function getOfferObject(array $offerParams)
 {
     if (!isset($offerParams["IBLOCK_ID"]) || intval($offerParams["IBLOCK_ID"]) <= 0) {
         throw new SystemException("Incorrect iBlock ID  (" . __CLASS__ . "::" . __METHOD__ . ")");
     }
     $arCatalog = \CCatalog::GetByIDExt($offerParams["IBLOCK_ID"]);
     if (empty($arCatalog)) {
         throw new SystemException("IBlock is not catalog. (" . __CLASS__ . "::" . __METHOD__ . ")");
     }
     $catalogType = $arCatalog["CATALOG_TYPE"];
     $catalogTypes = \CCatalogSKU::GetCatalogTypes();
     if (!in_array($catalogType, $catalogTypes)) {
         throw new SystemException("Unknown type of catalog (" . __CLASS__ . "::" . __METHOD__ . ")");
     }
     $result = array();
     switch ($catalogType) {
         case \CCatalogSKU::TYPE_CATALOG:
         case \CCatalogSKU::TYPE_OFFERS:
             $result = new ExportOffer($catalogType, $offerParams);
             break;
         case \CCatalogSKU::TYPE_PRODUCT:
         case \CCatalogSKU::TYPE_FULL:
             $result = new ExportOfferSKU($catalogType, $offerParams);
             break;
     }
     return $result;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:27,代码来源:exportoffercreator.php

示例2: GetProductInfo

 public static function GetProductInfo($intOfferID, $intIBlockID = 0)
 {
     $intOfferID = (int) $intOfferID;
     if ($intOfferID <= 0) {
         return false;
     }
     $intIBlockID = (int) $intIBlockID;
     if ($intIBlockID <= 0) {
         $intIBlockID = (int) CIBlockElement::GetIBlockByID($intOfferID);
     }
     if ($intIBlockID <= 0) {
         return false;
     }
     if (!isset(self::$arOfferCache[$intIBlockID])) {
         $arSkuInfo = CCatalogSKU::GetInfoByOfferIBlock($intIBlockID);
     } else {
         $arSkuInfo = self::$arOfferCache[$intIBlockID];
     }
     if (empty($arSkuInfo) || empty($arSkuInfo['SKU_PROPERTY_ID'])) {
         return false;
     }
     $rsItems = CIBlockElement::GetProperty($intIBlockID, $intOfferID, array(), array('ID' => $arSkuInfo['SKU_PROPERTY_ID']));
     if ($arItem = $rsItems->Fetch()) {
         $arItem['VALUE'] = (int) $arItem['VALUE'];
         if ($arItem['VALUE'] > 0) {
             return array('ID' => $arItem['VALUE'], 'IBLOCK_ID' => $arSkuInfo['PRODUCT_IBLOCK_ID'], 'OFFER_IBLOCK_ID' => $intIBlockID, 'SKU_PROPERTY_ID' => $arSkuInfo['SKU_PROPERTY_ID']);
         }
     }
     return false;
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:30,代码来源:catalog_sku.php

示例3: GetProductList

 public static function GetProductList($ID, $minCNT, $limit, $getParentOnly = false)
 {
     global $DB;
     $ID = (int) $ID;
     if ($ID <= 0) {
         return false;
     }
     $limit = (int) $limit;
     if ($limit < 0) {
         $limit = 0;
     }
     $minCNT = (int) $minCNT;
     if ($minCNT < 0) {
         $minCNT = 0;
     }
     $getParentOnly = $getParentOnly === true;
     $elementInclude = array($ID);
     $elementExclude = array();
     if (Loader::includeModule('catalog')) {
         $intIBlockID = (int) CIBlockElement::GetIBlockByID($ID);
         if ($intIBlockID == 0) {
             return false;
         }
         $skuInfo = CCatalogSKU::GetInfoByProductIBlock($intIBlockID);
         if (!empty($skuInfo)) {
             $itemsIterator = CIBlockElement::GetList(array(), array('IBLOCK_ID' => $skuInfo['IBLOCK_ID'], 'PROPERTY_' . $skuInfo['SKU_PROPERTY_ID'] => $ID), false, false, array('ID', 'IBLOCK_ID', 'PROPERTY_' . $skuInfo['SKU_PROPERTY_ID']));
             while ($item = $itemsIterator->Fetch()) {
                 $item['ID'] = (int) $item['ID'];
                 $elementInclude[] = $item['ID'];
                 $elementExclude[] = $item['ID'];
             }
         }
     }
     if ($getParentOnly) {
         $strSql = "select PARENT_PRODUCT_ID from b_sale_product2product where PRODUCT_ID IN (" . implode(',', $elementInclude) . ")";
         if (!empty($elementExclude)) {
             $strSql .= " and PARENT_PRODUCT_ID not in (" . implode(',', $elementExclude) . ")";
         }
         if ($minCNT > 0) {
             $strSql .= " and CNT >= " . $minCNT;
         }
         $strSql .= ' group by PARENT_PRODUCT_ID';
         if ($limit > 0) {
             $strSql .= " limit " . $limit;
         }
     } else {
         $strSql = "select * from b_sale_product2product where PRODUCT_ID in (" . implode(',', $elementInclude) . ")";
         if (!empty($elementExclude)) {
             $strSql .= " and PARENT_PRODUCT_ID not in (" . implode(',', $elementExclude) . ")";
         }
         if ($minCNT > 0) {
             $strSql .= " and CNT >= " . $minCNT;
         }
         $strSql .= " order by CNT desc, PRODUCT_ID asc";
         if ($limit > 0) {
             $strSql .= " limit " . $limit;
         }
     }
     return $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
 }
开发者ID:rasuldev,项目名称:torino,代码行数:60,代码来源:product.php

示例4: checkByShipment

 public function checkByShipment(\Bitrix\Sale\Shipment $shipment, array $restrictionParams, $deliveryId = 0)
 {
     if (!\Bitrix\Main\Loader::includeModule('iblock')) {
         return array();
     }
     if (!\Bitrix\Main\Loader::includeModule('catalog')) {
         return array();
     }
     $productIds = array();
     /** @var \Bitrix\Sale\ShipmentItem $shipmentItem */
     foreach ($shipment->getShipmentItemCollection() as $shipmentItem) {
         /** @var \Bitrix\Sale\BasketItem $basketItem */
         $basketItem = $shipmentItem->getBasketItem();
         if ($basketItem->getField('MODULE') != 'catalog') {
             continue;
         }
         $productId = intval($basketItem->getField('PRODUCT_ID'));
         $iblockId = (int) \CIBlockElement::getIBlockByID($productId);
         $info = \CCatalogSKU::getProductInfo($productId, $iblockId);
         if (!empty($info['ID'])) {
             $candidate = $info['ID'];
         } else {
             $candidate = $productId;
         }
         if (!in_array($candidate, $productIds)) {
             $productIds[] = $candidate;
         }
     }
     $categoriesIds = self::getGroupsIds($productIds);
     return $this->check($categoriesIds, $restrictionParams, $deliveryId);
 }
开发者ID:webgksupport,项目名称:alpina,代码行数:31,代码来源:byproductcategory.php

示例5: GetProductInfo

 public function GetProductInfo($intOfferID, $intIBlockID = 0)
 {
     $intOfferID = intval($intOfferID);
     if (0 >= $intOfferID) {
         return false;
     }
     $intIBlockID = intval($intIBlockID);
     if (0 >= $intIBlockID) {
         $rsItems = CIBlockElement::GetList(array(), array("ID" => $intOfferID, "SHOW_HISTORY" => "Y"), false, false, array('ID', 'IBLOCK_ID'));
         if ($arItem = $rsItems->Fetch()) {
             $intIBlockID = intval($arItem['IBLOCK_ID']);
         }
     }
     if (0 >= $intIBlockID) {
         return false;
     }
     $arSkuInfo = CCatalogSKU::GetInfoByOfferIBlock($intIBlockID);
     if (empty($arSkuInfo) || empty($arSkuInfo['SKU_PROPERTY_ID'])) {
         return false;
     }
     $rsItems = CIBlockElement::GetProperty($intIBlockID, $intOfferID, array(), array('ID' => $arSkuInfo['SKU_PROPERTY_ID']));
     if ($arItem = $rsItems->Fetch()) {
         $arItem['VALUE'] = intval($arItem['VALUE']);
         if (0 < $arItem['VALUE']) {
             return array('ID' => $arItem['VALUE'], 'IBLOCK_ID' => $arSkuInfo['PRODUCT_IBLOCK_ID']);
         }
     }
     return false;
 }
开发者ID:k-kalashnikov,项目名称:geekcon_new,代码行数:29,代码来源:catalog_sku.php

示例6: getOffers

 function getOffers()
 {
     if (!class_exists('\\CCatalogSKU')) {
         \CModule::IncludeModule('catalog');
     }
     $retval = array();
     $arInfo = \CCatalogSKU::GetInfoByProductIBlock($this->iblock_id);
     if (is_array($arInfo)) {
         $retval = \Cpeople\Classes\Block\Getter::instance()->setFilter(array('IBLOCK_ID' => $arInfo['IBLOCK_ID'], 'PROPERTY_' . $arInfo['SKU_PROPERTY_ID'] => $this->id))->setClassName('\\Cpeople\\Classes\\Catalog\\Offer')->get();
     }
     return empty_array($retval) ? false : $retval;
 }
开发者ID:ASDAFF,项目名称:bitrix_lib,代码行数:12,代码来源:Product.class.php

示例7: refresh

 /**
  * Common function, used to update/insert any product.
  *
  * @param int $productId			Id of product.
  * @param int $fuserId				User basket id.
  * @param string $siteId			Site id.
  * @param int $elementId			Parent id.
  * @param string $recommendationId	Bigdata recommendation id.
  *
  * @return int Id of row.
  */
 public static function refresh($productId, $fuserId, $siteId = SITE_ID, $elementId = 0, $recommendationId = '')
 {
     $connection = Application::getConnection();
     $productId = (int) $productId;
     if ($productId <= 0) {
         return -1;
     }
     $fuserId = (int) $fuserId;
     if ($fuserId <= 0) {
         return -1;
     }
     if (!is_string($siteId) || strlen($siteId) <= 0) {
         return -1;
     }
     $filter = array("FUSER_ID" => $fuserId, "SITE_ID" => $siteId);
     if ($elementId > 0) {
         $filter["ELEMENT_ID"] = $elementId;
         // Delete parent product id (for capability)
         if ($elementId != $productId) {
             $connection->query("DELETE FROM\n\t\t\t\t\t\t\t\t\t\tb_catalog_viewed_product\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tPRODUCT_ID = " . intval($elementId) . "\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\tFUSER_ID = " . intval($fuserId) . "\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\tSITE_ID = '" . $connection->getSqlHelper()->forSql($siteId) . "'");
         }
     } else {
         $iblockId = (int) \CIBlockElement::getIBlockByID($productId);
         if ($iblockId <= 0) {
             return -1;
         }
         $productInfo = \CCatalogSKU::getProductInfo($productId, $iblockId);
         // Concrete SKU ID
         if (!empty($productInfo)) {
             $filter['PRODUCT_ID'] = array();
             $siblings = array();
             // Delete parent product id (for capability)
             $connection->query("DELETE FROM\n\t\t\t\t\t\t\t\t\t\tb_catalog_viewed_product\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\tPRODUCT_ID = " . intval($productInfo['ID']) . "\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\tFUSER_ID = " . intval($fuserId) . "\n\t\t\t\t\t\t\t\t\t\tAND\n\t\t\t\t\t\t\t\t\t\tSITE_ID = '" . $connection->getSqlHelper()->forSql($siteId) . "'");
             $skuInfo = \CCatalogSKU::getInfoByOfferIBlock($iblockId);
             $skus = \CIBlockElement::getList(array(), array('IBLOCK_ID' => $iblockId, 'PROPERTY_' . $skuInfo['SKU_PROPERTY_ID'] => $productInfo['ID']), false, false, array('ID', 'IBLOCK_ID'));
             while ($oneSku = $skus->fetch()) {
                 $siblings[] = $oneSku['ID'];
             }
             $filter["PRODUCT_ID"] = $siblings;
         } else {
             $filter["PRODUCT_ID"] = $productId;
         }
     }
     $iterator = static::getList(array("filter" => $filter, "select" => array("ID", "FUSER_ID", "DATE_VISIT", "PRODUCT_ID", "SITE_ID", "VIEW_COUNT")));
     if ($row = $iterator->fetch()) {
         static::update($row["ID"], array("PRODUCT_ID" => $productId, "DATE_VISIT" => new \Bitrix\Main\Type\DateTime(), 'VIEW_COUNT' => $row['VIEW_COUNT'] + 1, "ELEMENT_ID" => $elementId, "RECOMMENDATION" => $recommendationId));
         return $row['ID'];
     } else {
         $result = static::add(array("FUSER_ID" => $fuserId, "DATE_VISIT" => new \Bitrix\Main\Type\DateTime(), "PRODUCT_ID" => $productId, "ELEMENT_ID" => $elementId, "SITE_ID" => $siteId, "VIEW_COUNT" => 1, "RECOMMENDATION" => $recommendationId));
         return $result->getId();
     }
 }
开发者ID:ASDAFF,项目名称:1C_Bitrix_info_site,代码行数:63,代码来源:catalogviewedproduct.php

示例8: resolveElement

 /**
  * If elementId is an offer, then it's product identifier returned
  * Otherwise $elementId returned.
  *
  * @param integer $iblockId Information block identifier.
  * @param integer $elementId Element identifier.
  *
  * @return integer
  */
 public static function resolveElement($iblockId, $elementId)
 {
     if (self::$catalog === null) {
         self::$catalog = \Bitrix\Main\Loader::includeModule("catalog");
     }
     if (self::$catalog) {
         $catalog = \CCatalogSKU::getProductInfo($elementId, $iblockId);
         if (!empty($catalog) && is_array($catalog)) {
             return $catalog["ID"];
         }
     }
     return $elementId;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:22,代码来源:manager.php

示例9: checkOffers

 private function checkOffers($product_id)
 {
     if (CCatalogSKU::IsExistOffers($product_id, $this->iblock_id)) {
         $arSelect = array("IBLOCK_ID", "ID", "CATALOG_GROUP_1");
         $arFilter = array("PROPERTY_CML2_LINK" => $product_id, "ACTIVE" => "Y");
         $res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect);
         if ($ob = $res->GetNextElement()) {
             $arFields = $ob->GetFields();
             return $arFields['CATALOG_PRICE_1'];
         }
     } else {
         return false;
     }
 }
开发者ID:ASDAFF,项目名称:mp,代码行数:14,代码来源:.index.items.php

示例10: getOffers

 protected function getOffers()
 {
     $arPropertyMap = array();
     $arSelectedPropTypes = array('S', 'N', 'L', 'E', 'G');
     $this->arSelectOfferProps = array();
     $arOffers = \CCatalogSKU::GetInfoByProductIBlock($this->iBlockId);
     if (empty($arOffers['IBLOCK_ID'])) {
         return array();
     }
     $this->intOfferIBlockID = $arOffers['IBLOCK_ID'];
     $rsOfferIBlocks = \CIBlock::GetByID($this->intOfferIBlockID);
     if (!($this->arOfferIBlock = $rsOfferIBlocks->Fetch())) {
         throw new SystemException("Bad offers iBlock ID  (" . __CLASS__ . "::" . __METHOD__ . ")");
     }
     $rsProps = \CIBlockProperty::GetList(array('SORT' => 'ASC', 'NAME' => 'ASC'), array('IBLOCK_ID' => $this->intOfferIBlockID, 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'));
     while ($arProp = $rsProps->Fetch()) {
         $arProp['ID'] = (int) $arProp['ID'];
         if ($arOffers['SKU_PROPERTY_ID'] != $arProp['ID']) {
             $arProp['USER_TYPE'] = (string) $arProp['USER_TYPE'];
             $arProp['CODE'] = (string) $arProp['CODE'];
             $this->arIblock['OFFERS_PROPERTY'][$arProp['ID']] = $arProp;
             $this->arProperties[$arProp['ID']] = $arProp;
             if (in_array($arProp['PROPERTY_TYPE'], $arSelectedPropTypes)) {
                 $this->arSelectOfferProps[] = $arProp['ID'];
             }
             if ($arProp['CODE'] !== '') {
                 foreach ($this->arIblock['PROPERTY'] as &$arMainProp) {
                     if ($arMainProp['CODE'] == $arProp['CODE']) {
                         $arPropertyMap[$arProp['ID']] = $arMainProp['CODE'];
                         break;
                     }
                 }
                 if (isset($arMainProp)) {
                     unset($arMainProp);
                 }
             }
         }
     }
     $this->arOfferIBlock['LID'] = $this->arIblock['LID'];
     $this->arOfferIBlock['PROPERTY'] = array();
     $rsProps = \CIBlockProperty::GetList(array('SORT' => 'ASC', 'NAME' => 'ASC'), array('IBLOCK_ID' => $this->intOfferIBlockID, 'ACTIVE' => 'Y', 'CHECK_PERMISSIONS' => 'N'));
     while ($arProp = $rsProps->Fetch()) {
         $arProp['ID'] = (int) $arProp['ID'];
         $arProp['USER_TYPE'] = (string) $arProp['USER_TYPE'];
         $arProp['CODE'] = (string) $arProp['CODE'];
         $this->arOfferIBlock['PROPERTY'][$arProp['ID']] = $arProp;
     }
     return $arOffers;
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:49,代码来源:exportoffersku.php

示例11: init

 /**
  * Initializes internal object state. Must be called before usage.
  *
  * @throws \Bitrix\Main\LoaderException
  * @return void
  */
 public function init()
 {
     $this->dictionary = new Dictionary($this->iblockId);
     $this->storage = new Storage($this->iblockId);
     if (self::$catalog === null) {
         self::$catalog = \Bitrix\Main\Loader::includeModule("catalog");
     }
     if (self::$catalog) {
         $catalog = \CCatalogSKU::getInfoByProductIBlock($this->iblockId);
         if (!empty($catalog) && is_array($catalog)) {
             $this->skuIblockId = $catalog["IBLOCK_ID"];
             $this->skuPropertyId = $catalog["SKU_PROPERTY_ID"];
         }
     }
 }
开发者ID:DarneoStudio,项目名称:bitrix,代码行数:21,代码来源:indexer.php

示例12: __construct

 /**
  * @param integer $iblockId Information block identifier.
  */
 public function __construct($iblockId)
 {
     $this->iblockId = intval($iblockId);
     $this->valid = \CIBlock::getArrayByID($this->iblockId, "PROPERTY_INDEX") === "Y";
     if (Loader::includeModule("catalog")) {
         $catalogInfo = \CCatalogSKU::getInfoByProductIBlock($this->iblockId);
         if (!empty($catalogInfo) && is_array($catalogInfo)) {
             $this->skuIblockId = $catalogInfo["IBLOCK_ID"];
             $this->skuPropertyId = $catalogInfo["SKU_PROPERTY_ID"];
             $this->valid = $this->valid && \CIBlock::getArrayByID($this->skuIblockId, "PROPERTY_INDEX") === "Y";
         }
     }
     $this->dictionary = new \Bitrix\Iblock\PropertyIndex\Dictionary($this->iblockId);
     $this->storage = new \Bitrix\Iblock\PropertyIndex\Storage($this->iblockId);
 }
开发者ID:ASDAFF,项目名称:1C_Bitrix_info_site,代码行数:18,代码来源:querybuilder.php

示例13: __construct

 /**
  * @param integer $iblockId Information block identifier.
  * @param integer $elementId Element identifier.
  *
  * @throws \Bitrix\Main\LoaderException
  */
 public function __construct($iblockId, $elementId)
 {
     $this->iblockId = intval($iblockId);
     $this->elementId = intval($elementId);
     if (self::$catalog === null) {
         self::$catalog = \Bitrix\Main\Loader::includeModule("catalog");
     }
     if (self::$catalog) {
         $catalog = \CCatalogSKU::getInfoByProductIBlock($this->iblockId);
         if (!empty($catalog) && is_array($catalog)) {
             $this->skuIblockId = $catalog["IBLOCK_ID"];
             $this->skuPropertyId = $catalog["SKU_PROPERTY_ID"];
         }
     }
 }
开发者ID:mrdeadmouse,项目名称:u136006,代码行数:21,代码来源:element.php

示例14: GetProductInfo

 public static function GetProductInfo($intOfferID, $intIBlockID = 0)
 {
     $intOfferID = (int) $intOfferID;
     if ($intOfferID <= 0) {
         return false;
     }
     if (!isset(self::$parentCache[$intOfferID])) {
         self::$parentCache[$intOfferID] = false;
         $intIBlockID = (int) $intIBlockID;
         if ($intIBlockID <= 0) {
             $intIBlockID = (int) CIBlockElement::GetIBlockByID($intOfferID);
         }
         if ($intIBlockID <= 0) {
             return self::$parentCache[$intOfferID];
         }
         if (!isset(self::$arOfferCache[$intIBlockID])) {
             $skuInfo = CCatalogSKU::GetInfoByOfferIBlock($intIBlockID);
         } else {
             $skuInfo = self::$arOfferCache[$intIBlockID];
         }
         if (empty($skuInfo) || empty($skuInfo['SKU_PROPERTY_ID'])) {
             return self::$parentCache[$intOfferID];
         }
         $conn = Application::getConnection();
         $helper = $conn->getSqlHelper();
         if ($skuInfo['VERSION'] == 2) {
             $productField = $helper->quote('PROPERTY_' . $skuInfo['SKU_PROPERTY_ID']);
             $sqlQuery = 'select ' . $productField . ' as ID from ' . $helper->quote('b_iblock_element_prop_s' . $skuInfo['IBLOCK_ID']) . ' where ' . $helper->quote('IBLOCK_ELEMENT_ID') . ' = ' . $intOfferID;
         } else {
             $productField = $helper->quote('VALUE_NUM');
             $sqlQuery = 'select ' . $productField . ' as ID from ' . $helper->quote('b_iblock_element_property') . ' where ' . $helper->quote('IBLOCK_PROPERTY_ID') . ' = ' . $skuInfo['SKU_PROPERTY_ID'] . ' and ' . $helper->quote('IBLOCK_ELEMENT_ID') . ' = ' . $intOfferID;
         }
         unset($productField);
         $parentIterator = $conn->query($sqlQuery);
         if ($parent = $parentIterator->fetch()) {
             $parent['ID'] = (int) $parent['ID'];
             if ($parent['ID'] > 0) {
                 self::$parentCache[$intOfferID] = array('ID' => $parent['ID'], 'IBLOCK_ID' => $skuInfo['PRODUCT_IBLOCK_ID'], 'OFFER_IBLOCK_ID' => $intIBlockID, 'SKU_PROPERTY_ID' => $skuInfo['SKU_PROPERTY_ID']);
             }
         }
         unset($parent, $parentIterator, $sqlQuery, $helper, $conn, $skuInfo);
     }
     return self::$parentCache[$intOfferID];
 }
开发者ID:akniyev,项目名称:itprom_dobrohost,代码行数:44,代码来源:catalog_sku.php

示例15: refresh

 /**
  * Common function, used to update/insert any product.
  *
  * @param int $productId   Id of product.
  * @param int $fuserId   User basket id.
  * @param string $siteId      Site id.
  *
  * @return int Id of row.
  */
 public static function refresh($productId, $fuserId, $siteId = SITE_ID)
 {
     $connection = Application::getConnection();
     $productId = (int) $productId;
     if ($productId <= 0) {
         return -1;
     }
     $iblockID = (int) \CIBlockElement::getIBlockByID($productId);
     if ($iblockID <= 0) {
         return -1;
     }
     $productInfo = \CCatalogSKU::getProductInfo($productId, $iblockID);
     $fuserId = (int) $fuserId;
     if ($fuserId <= 0) {
         return -1;
     }
     if (!is_string($siteId) || strlen($siteId) <= 0) {
         return -1;
     }
     $filter = array("FUSER_ID" => $fuserId, "SITE_ID" => $siteId);
     // Concrete SKU ID
     if (!empty($productInfo)) {
         $filter['PRODUCT_ID'] = array();
         $siblings = array();
         // Delete parent product id (for capability)
         $connection->query("DELETE FROM b_catalog_viewed_product WHERE PRODUCT_ID = {$productInfo['ID']} AND FUSER_ID = {$fuserId} AND SITE_ID = '{$siteId}'");
         $skuInfo = \CCatalogSKU::getInfoByOfferIBlock($iblockID);
         $skus = \CIBlockElement::getList(array(), array('IBLOCK_ID' => $iblockID, 'PROPERTY_' . $skuInfo['SKU_PROPERTY_ID'] => $productInfo['ID']), false, false, array('ID', 'IBLOCK_ID'));
         while ($oneSku = $skus->fetch()) {
             $siblings[] = $oneSku['ID'];
         }
         $filter["PRODUCT_ID"] = $siblings;
     } else {
         $filter["PRODUCT_ID"] = $productId;
     }
     $iterator = static::getList(array("filter" => $filter, "select" => array("ID", "FUSER_ID", "DATE_VISIT", "PRODUCT_ID", "SITE_ID", "VIEW_COUNT")));
     if ($row = $iterator->fetch()) {
         static::update($row["ID"], array("PRODUCT_ID" => $productId, "DATE_VISIT" => new \Bitrix\Main\Type\DateTime(), 'VIEW_COUNT' => $row['VIEW_COUNT'] + 1));
         return $row['ID'];
     } else {
         $result = static::add(array("FUSER_ID" => $fuserId, "DATE_VISIT" => new \Bitrix\Main\Type\DateTime(), "PRODUCT_ID" => $productId, "SITE_ID" => $siteId, "VIEW_COUNT" => 1));
         return $result->getId();
     }
 }
开发者ID:rasuldev,项目名称:torino,代码行数:53,代码来源:catalogviewedproduct.php


注:本文中的CCatalogSKU类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。