Beispiel #1
0
 /**
  * 2016-07-18
  * @return mixed|null
  * @throws CouldNotSaveException
  */
 private function _place()
 {
     /** @var IQM|QM $qm */
     $qm = df_o(IQM::class);
     /** @var mixed $result */
     try {
         BillingAddress::disable(!$this->ss()->askForBillingAddress());
         try {
             /** @var int $orderId */
             $orderId = $qm->placeOrder($this->quoteId());
         } finally {
             BillingAddress::restore();
         }
         $result = df_order($orderId)->getPayment()->getAdditionalInformation(PlaceOrder::DATA);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__($this->message($e)), $e);
     }
     return $result;
 }
Beispiel #2
0
 /**
  * 2016-07-28
  * @override
  * @see ObserverInterface::execute()
  * @used-by \Magento\Framework\Event\Invoker\InvokerDefault::_callObserverMethod()
  * @param O $o
  * @return void
  */
 public function execute(O $o)
 {
     /** @var Provider $provider */
     $provider = $o[Plugin::PROVIDER];
     /** @var ISearchResult|ApiSearchResult|UiSearchResult|OrderGC|InvoiceGC|CreditmemoGC $result */
     $result = $o[Plugin::RESULT];
     if (in_array($provider->getName(), ['sales_order_grid_data_source'])) {
         /**
          * 2016-07-28
          * https://github.com/magento/magento2/blob/2.1.0/lib/internal/Magento/Framework/View/Element/UiComponent/DataProvider/SearchResult.php#L37-L40
          * @see \Magento\Framework\View\Element\UiComponent\DataProvider\SearchResult::$document
          *
          * Структура документа описана здесь: https://mage2.pro/t/1908
          */
         /** @var string $cacheKey */
         $cacheKey = __METHOD__;
         /** @var string $prop */
         $prop = 'payment_method';
         df_map(function (Document $item) use($cacheKey, $prop) {
             /** @var string|null $methodCode */
             $methodCode = $item[$prop];
             if ($methodCode && df_starts_with($methodCode, 'dfe_')) {
                 /** @var int $id */
                 $id = $item['entity_id'];
                 /**
                  * 2016-07-29
                  * Эта операция очень ресурсоёмка:
                  * для каждой строки таблицы заказов она делает кучу запросов к базе данных.
                  * Поэтому кэшируем результаты в постоянном кэше.
                  */
                 $item[$prop] = df_cache_get_simple([$cacheKey, $id], function () use($id) {
                     /** @var Method $method */
                     $method = df_order($id)->getPayment()->getMethodInstance();
                     return $method->titleDetailed();
                 });
             }
         }, $result);
     }
 }