コード例 #1
0
ファイル: providerbase.php プロジェクト: Satariall/izurit
 /**
  * @param Basket $basketCollection
  * @param array $select
  * @param BasketItem $refreshItem
  * @return array
  * @throws NotSupportedException
  */
 public static function getProductData(Basket $basketCollection, array $select = array(), BasketItem $refreshItem = null)
 {
     $result = array();
     $orderId = null;
     $userId = null;
     $siteId = null;
     $currency = null;
     if (($order = $basketCollection->getOrder()) !== null) {
         $userId = $order->getUserId();
         $siteId = $order->getSiteId();
         $currency = $order->getCurrency();
     }
     if ($userId === null) {
         static $usersIds = array();
         if (empty($usersIds[$basketCollection->getFUserId(true)])) {
             $usersIds[$basketCollection->getFUserId(true)] = \CSaleUser::getUserID($basketCollection->getFUserId(true));
         }
         $userId = $usersIds[$basketCollection->getFUserId(true)];
     }
     if ($siteId === null) {
         $siteId = $basketCollection->getSiteId();
     }
     if ($siteId === null) {
         return array();
     }
     if ($currency === null) {
         $currency = Internals\SiteCurrencyTable::getSiteCurrency($siteId);
         if (!$currency) {
             $currency = Currency\CurrencyManager::getBaseCurrency();
         }
     }
     $basketList = static::makeArrayFromBasketCollection($basketCollection, $refreshItem);
     $basketProviderMap = static::createProviderBasketMap($basketList, array('QUANTITY', 'RENEWAL'));
     $basketProviderList = static::redistributeToProviders($basketProviderMap);
     if (!empty($basketProviderList)) {
         $needPrice = in_array('PRICE', $select);
         $needBasePrice = in_array('BASE_PRICE', $select);
         $needCoupons = in_array('COUPONS', $select);
         $data = array('USER_ID' => (int) $userId, 'SITE_ID' => $siteId, 'CURRENCY' => $currency, 'CHECK_QUANTITY' => in_array('QUANTITY', $select) ? 'Y' : 'N', 'CHECK_PRICE' => $needPrice ? 'Y' : 'N', 'CHECK_COUPONS' => $needCoupons ? 'Y' : 'N', 'RENEWAL' => in_array('RENEWAL', $select) ? 'Y' : 'N');
         if ($needBasePrice) {
             $data['CHECK_DISCOUNT'] = 'N';
         }
         $useOrderProduct = false;
         if ($needPrice) {
             $useOrderProduct = true;
         }
         if ($needCoupons) {
             $useOrderProduct = false;
         }
         unset($needCoupons, $needPrice);
         foreach ($basketProviderList as $provider => $providerBasketItemList) {
             if ($provider instanceof Provider) {
                 throw new NotSupportedException('provider not supported');
             } elseif ($provider && array_key_exists("IBXSaleProductProvider", class_implements($provider))) {
                 foreach ($providerBasketItemList as $providerBasketItem) {
                     $currentUseOrderProduct = $useOrderProduct;
                     if (!isset($providerBasketItem['BASKET_ID']) || (int) $providerBasketItem['BASKET_ID'] <= 0) {
                         $currentUseOrderProduct = false;
                     }
                     $providerFields = $data;
                     if ($providerBasketItem['BASKET_ITEM']->isBundleChild()) {
                         $providerFields['CHECK_DISCOUNT'] = 'N';
                     }
                     $providerFields['PRODUCT_ID'] = $providerBasketItem['PRODUCT_ID'];
                     $providerFields['QUANTITY'] = $providerBasketItem['QUANTITY'];
                     $hasTrustData = false;
                     $trustData = static::getTrustData($siteId, $providerBasketItem['MODULE'], $providerBasketItem['PRODUCT_ID']);
                     if (static::isReadTrustData() === true && !empty($trustData) && is_array($trustData)) {
                         $hasTrustData = true;
                         $resultProductData = $trustData;
                         foreach (static::getProductDataRequiredFields() as $requiredField) {
                             if (!array_key_exists($requiredField, $resultProductData)) {
                                 $hasTrustData = false;
                                 break;
                             }
                         }
                         if ($hasTrustData && in_array('PRICE', $select)) {
                             foreach (static::getProductDataRequiredPriceFields() as $requiredField) {
                                 if (!array_key_exists($requiredField, $resultProductData)) {
                                     $hasTrustData = false;
                                     break;
                                 }
                             }
                         }
                     }
                     if (!$hasTrustData) {
                         $resultProductData = $currentUseOrderProduct ? $provider::OrderProduct($providerFields) : $provider::GetProductData($providerFields);
                     }
                     $basketCode = $providerBasketItem['BASKET_ITEM']->getBasketCode();
                     $result[$basketCode] = $resultProductData;
                 }
             } else {
                 foreach ($providerBasketItemList as $providerBasketItem) {
                     $resultProductData = \CSaleBasket::executeCallbackFunction($providerBasketItem['CALLBACK_FUNC'], $providerBasketItem['MODULE'], $providerBasketItem['PRODUCT_ID'], $providerBasketItem['QUANTITY']);
                     $basketCode = $providerBasketItem['BASKET_ITEM']->getBasketCode();
                     $result[$basketCode] = $resultProductData;
                 }
             }
         }
     }
     return $result;
 }