コード例 #1
0
ファイル: AbstractApi.php プロジェクト: nja78/magento2
 /**
  * Prepare line items request
  *
  * Returns true if there were line items added
  *
  * @param array &$request
  * @param int $i
  * @return true|null
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _exportLineItems(array &$request, $i = 0)
 {
     if (!$this->_cart) {
         return;
     }
     // always add cart totals, even if line items are not requested
     if ($this->_lineItemTotalExportMap) {
         foreach ($this->_cart->getAmounts() as $key => $total) {
             if (isset($this->_lineItemTotalExportMap[$key])) {
                 // !empty($total)
                 $privateKey = $this->_lineItemTotalExportMap[$key];
                 $request[$privateKey] = $this->_filterAmount($total);
             }
         }
     }
     // add cart line items
     $items = $this->_cart->getAllItems();
     if (empty($items) || !$this->getIsLineItemsEnabled()) {
         return;
     }
     $result = null;
     foreach ($items as $item) {
         foreach ($this->_lineItemExportItemsFormat as $publicKey => $privateFormat) {
             $result = true;
             $value = $item->getDataUsingMethod($publicKey);
             if (isset($this->_lineItemExportItemsFilters[$publicKey])) {
                 $callback = $this->_lineItemExportItemsFilters[$publicKey];
                 $value = call_user_func([$this, $callback], $value);
             }
             if (is_float($value)) {
                 $value = $this->_filterAmount($value);
             }
             $request[sprintf($privateFormat, $i)] = $value;
         }
         $i++;
     }
     return $result;
 }
コード例 #2
0
ファイル: CartTest.php プロジェクト: pradeep-wagento/magento2
 public function testGetAmounts()
 {
     $totals = $this->_prepareValidModelData();
     $this->assertEquals($totals, $this->_model->getAmounts());
 }