Example #1
0
 /**
  * Load discount data from db.
  * @param int $id					Discount id.
  * @param array $discount			Exist discount data.
  * @return bool|array
  */
 protected static function loadFromDatabase($id, $discount)
 {
     $select = array();
     if (!isset($discount['NAME'])) {
         $select['NAME'] = true;
     }
     if (empty($discount['CONDITIONS'])) {
         $select['CONDITIONS_LIST'] = true;
     }
     if (empty($discount['UNPACK'])) {
         $select['UNPACK'] = true;
     }
     if (empty($discount['USE_COUPONS'])) {
         $discount['USE_COUPONS'] = !empty($discount['COUPON']) ? 'Y' : 'N';
     }
     if (!isset($discount['SORT'])) {
         $select['SORT'] = true;
     }
     if (!isset($discount['PRIORITY'])) {
         $select['PRIORITY'] = true;
     }
     if (!isset($discount['LAST_DISCOUNT'])) {
         $select['LAST_DISCOUNT'] = true;
     }
     if (!isset($discount['TYPE']) || $discount['TYPE'] != Catalog\DiscountTable::TYPE_DISCOUNT && $discount['TYPE'] != Catalog\DiscountTable::TYPE_DISCOUNT_SAVE) {
         $select['TYPE'] = true;
     }
     if (!isset($discount['VALUE_TYPE'])) {
         $select['VALUE_TYPE'] = true;
         $select['VALUE'] = true;
         $select['MAX_DISCOUNT'] = true;
         $select['CURRENCY'] = true;
     } else {
         if (!isset($discount['VALUE'])) {
             $select['VALUE'] = true;
         }
         if (!isset($discount['CURRENCY'])) {
             $select['CURRENCY'] = true;
         }
         if ($discount['VALUE_TYPE'] == Catalog\DiscountTable::VALUE_TYPE_PERCENT && !isset($discount['MAX_VALUE'])) {
             $select['MAX_DISCOUNT'] = true;
         }
     }
     $selectKeys = array_keys($select);
     if (!empty($select)) {
         $discountIterator = Catalog\DiscountTable::getList(array('select' => $selectKeys, 'filter' => array('=ID' => $id)));
         $loadData = $discountIterator->fetch();
         if (empty($loadData)) {
             return false;
         }
         $discount = array_merge($loadData, $discount);
         if (isset($discount['CONDITIONS_LIST'])) {
             $discount['CONDITIONS'] = $discount['CONDITIONS_LIST'];
             unset($discount['CONDITIONS_LIST']);
         }
         if (isset($discount['MAX_DISCOUNT'])) {
             $discount['MAX_VALUE'] = $discount['MAX_DISCOUNT'];
             unset($discount['MAX_DISCOUNT']);
         }
         unset($loadData, $discountIterator);
     }
     $discount['DISCOUNT_ID'] = $id;
     if (empty($discount['MODULE_ID'])) {
         $discount['MODULE_ID'] = 'catalog';
     }
     if (array_key_exists('HANDLERS', $discount)) {
         if (!empty($discount['HANDLERS']['MODULES']) && empty($discount['MODULES'])) {
             $discount['MODULES'] = $discount['HANDLERS']['MODULES'];
         }
         unset($discount['HANDLERS']);
     }
     if (empty($discount['MODULES'])) {
         $discount['MODULES'] = array();
         $conn = Main\Application::getConnection();
         $helper = $conn->getSqlHelper();
         $moduleIterator = $conn->query('select MODULE_ID from ' . $helper->quote('b_catalog_discount_module') . ' where ' . $helper->quote('DISCOUNT_ID') . ' = ' . $id);
         while ($module = $moduleIterator->fetch()) {
             $discount['MODULES'][] = $module['MODULE_ID'];
         }
         unset($module, $moduleIterator, $helper, $conn);
         if (!in_array('catalog', $discount['MODULES'])) {
             $discount['MODULES'][] = 'catalog';
         }
     }
     self::$typeCache[$id] = $discount['TYPE'];
     return $discount;
 }
Example #2
0
 /**
  * Check discount for convert.
  *
  * @param array &$discountData			Discount data.
  * @return void
  * @throws Main\ArgumentException
  * @throws Main\LoaderException
  */
 private static function checkMigrateDiscount(&$discountData)
 {
     if (self::$catalogIncluded === null) {
         self::$catalogIncluded = Main\Loader::includeModule('catalog');
     }
     if (!self::$catalogIncluded) {
         return;
     }
     $coupon = $discountData['COUPON'];
     $hash = md5($discountData['DISCOUNT_ID'] . '|' . $discountData['NAME']);
     if (!isset(self::$catalogDiscountsCache[$hash])) {
         $discountIterator = Catalog\DiscountTable::getList(array('select' => array('*'), 'filter' => array('=ID' => $discountData['DISCOUNT_ID'], '=NAME' => $discountData['NAME'])));
         $existDiscount = $discountIterator->fetch();
         unset($discountIterator);
         if (!empty($existDiscount)) {
             if ($existDiscount['NAME'] != $discountData['NAME']) {
                 self::createEmptyDiscount($discountData);
             } else {
                 if ($existDiscount['TYPE'] == Catalog\DiscountTable::TYPE_DISCOUNT_SAVE) {
                     self::createEmptyDiscount($discountData, true);
                 } else {
                     $existDiscount['COUPON'] = $discountData['COUPON'];
                     $discountData = self::executeDiscountProvider('catalog', $existDiscount);
                 }
             }
         } else {
             self::createEmptyDiscount($discountData);
         }
         unset($existDiscount);
         self::$catalogDiscountsCache[$hash] = $discountData;
     } else {
         $discountData = self::$catalogDiscountsCache[$hash];
     }
     $discountData['COUPON'] = $coupon;
 }