Esempio n. 1
0
 public static function checkQuantity($ID, $productFields)
 {
     $checkNeed = isset($productFields['QUANTITY']) || isset($productFields['QUANTITY_TRACE']) || isset($productFields['CAN_BUY_ZERO']);
     if (!$checkNeed) {
         return;
     }
     $productIterator = ProductTable::getList(array('filter' => array('=ID' => $ID), 'select' => array('QUANTITY', 'QUANTITY_TRACE', 'CAN_BUY_ZERO')));
     $product = $productIterator->fetch();
     if ($product) {
         if ($product["QUANTITY_TRACE"] == "Y" && $product['CAN_BUY_ZERO'] == 'N') {
             $linkIterator = LinkTable::getList(array("filter" => array("=LINK_TYPE" => LinkTable::TYPE_IBLOCK_ELEMENT, "=LINK_ID" => $ID, array(array("=BANNER.AUTO_QUANTITY_OFF" => YandexBannerTable::ACTIVE), array("=BANNER.AUTO_QUANTITY_ON" => YandexBannerTable::ACTIVE), 'LOGIC' => "OR")), "select" => array("BANNER_ID", "AUTO_QUANTITY_ON" => "BANNER.AUTO_QUANTITY_ON", "AUTO_QUANTITY_OFF" => "BANNER.AUTO_QUANTITY_OFF")));
             $zeroQuantity = $product['QUANTITY'] <= 0;
             $linkIdMark = array();
             $linkIdUnMark = array();
             while ($link = $linkIterator->fetch()) {
                 $linkIdMark[] = $link["BANNER_ID"];
                 if ($zeroQuantity && $link["AUTO_QUANTITY_ON"] == YandexBannerTable::MARKED || !$zeroQuantity && $link["AUTO_QUANTITY_OFF"] == YandexBannerTable::MARKED) {
                     $linkIdUnMark[] = $link["BANNER_ID"];
                 }
             }
             if (count($linkIdMark) > 0) {
                 if ($zeroQuantity) {
                     YandexBannerTable::markStopped($linkIdMark);
                 } else {
                     YandexBannerTable::markResumed($linkIdMark);
                 }
                 if (count($linkIdUnMark) > 0) {
                     if ($zeroQuantity) {
                         YandexBannerTable::unMarkResumed($linkIdUnMark);
                     } else {
                         YandexBannerTable::unMarkStopped($linkIdUnMark);
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Returns product data.
  *
  * @param array &$productData			Product data.
  * @param array $entityData				Entity data.
  * @param array $iblockData				Iblock list data.
  * @return void
  */
 protected static function getProductData(&$productData, $entityData, $iblockData)
 {
     if (!empty($iblockData['iblockElement'])) {
         $productList = array_keys($productData);
         if (!empty($entityData['iblockFields'])) {
             $elementIterator = Iblock\ElementTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['iblockFields'])), 'filter' => array('@ID' => $productList)));
             while ($element = $elementIterator->fetch()) {
                 $element['ID'] = (int) $element['ID'];
                 $fields = array();
                 foreach ($entityData['iblockFields'] as $key => $alias) {
                     $fields[$alias] = $element[$key];
                 }
                 unset($key, $alias);
                 $productData[$element['ID']] = empty($productData[$element['ID']]) ? $fields : array_merge($productData[$element['ID']], $fields);
                 unset($fields);
             }
         }
         if ($entityData['sections']) {
             $productSection = array_fill_keys($productList, array());
             $elementSectionIterator = Iblock\SectionElementTable::getList(array('select' => array('*'), 'filter' => array('@IBLOCK_ELEMENT_ID' => $productList)));
             while ($elementSection = $elementSectionIterator->fetch()) {
                 $elementSection['IBLOCK_ELEMENT_ID'] = (int) $elementSection['IBLOCK_ELEMENT_ID'];
                 $elementSection['IBLOCK_SECTION_ID'] = (int) $elementSection['IBLOCK_SECTION_ID'];
                 $elementSection['ADDITIONAL_PROPERTY_ID'] = (int) $elementSection['ADDITIONAL_PROPERTY_ID'];
                 if ($elementSection['ADDITIONAL_PROPERTY_ID'] > 0) {
                     continue;
                 }
                 $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$elementSection['IBLOCK_SECTION_ID']] = true;
                 $parentSectionIterator = \CIBlockSection::getNavChain(0, $elementSection['IBLOCK_SECTION_ID'], array('ID'));
                 while ($parentSection = $parentSectionIterator->fetch()) {
                     $parentSection['ID'] = (int) $parentSection['ID'];
                     $productSection[$elementSection['IBLOCK_ELEMENT_ID']][$parentSection['ID']] = true;
                 }
                 unset($parentSection, $parentSectionIterator);
             }
             unset($elementSection, $elementSectionIterator);
             foreach ($productSection as $element => $sections) {
                 $productData[$element]['SECTION_ID'] = array_keys($sections);
             }
             unset($element, $sections, $productSection);
         }
         if (!empty($entityData['needProperties'])) {
             $propertyValues = array_fill_keys($productList, array());
             foreach ($entityData['needProperties'] as $iblock => $propertyList) {
                 if (empty($iblockData['iblockElement'][$iblock])) {
                     continue;
                 }
                 $filter = array('ID' => $iblockData['iblockElement'][$iblock], 'IBLOCK_ID' => $iblock);
                 \CTimeZone::disable();
                 \CIBlockElement::getPropertyValuesArray($propertyValues, $iblock, $filter, array('ID' => $propertyList));
                 \CTimeZone::enable();
             }
             unset($filter, $iblock, $propertyList);
             self::convertProperties($productData, $propertyValues, $entityData, $iblockData);
         }
         if (!empty($entityData['catalogFields'])) {
             $productIterator = Catalog\ProductTable::getList(array('select' => array_merge(array('ID'), array_keys($entityData['catalogFields'])), 'filter' => array('@ID' => $productList)));
             while ($product = $productIterator->fetch()) {
                 $product['ID'] = (int) $product['ID'];
                 $fields = array();
                 foreach ($entityData['catalogFields'] as $key => $alias) {
                     $fields[$alias] = $product[$key];
                 }
                 unset($key, $alias);
                 $productData[$product['ID']] = empty($productData[$product['ID']]) ? $fields : array_merge($productData[$product['ID']], $fields);
                 unset($fields);
             }
             unset($product, $productIterator);
         }
         if (!empty($iblockData['skuIblockList'])) {
             self::getParentProducts($productData, $entityData, $iblockData);
         }
     }
 }