public function testHasNegativeItemAmount() { $this->_model->addCustomItem('item1', 1, 2.1); $this->assertFalse($this->_model->hasNegativeItemAmount()); $this->_model->addCustomItem('item1', 1, -1.3); $this->assertTrue($this->_model->hasNegativeItemAmount()); }
/** * 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; }
/** * Set shipping options to api * @param \Magento\Paypal\Model\Cart $cart * @param \Magento\Quote\Model\Quote\Address|null $address * @return void */ private function setShippingOptions(PaypalCart $cart, Address $address = null) { // for included tax always disable line items (related to paypal amount rounding problem) $this->_api->setIsLineItemsEnabled($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS)); // add shipping options if needed and line items are available $cartItems = $cart->getAllItems(); if ($this->_config->getValue(PaypalConfig::TRANSFER_CART_LINE_ITEMS) && $this->_config->getValue(PaypalConfig::TRANSFER_SHIPPING_OPTIONS) && !empty($cartItems)) { if (!$this->_quote->getIsVirtual()) { $options = $this->_prepareShippingOptions($address, true); if ($options) { $this->_api->setShippingOptionsCallbackUrl($this->_coreUrl->getUrl('*/*/shippingOptionsCallback', ['quote_id' => $this->_quote->getId()]))->setShippingOptions($options); } } } }