本文整理汇总了PHP中Magento\Sales\Model\Order::getDiscountAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::getDiscountAmount方法的具体用法?PHP Order::getDiscountAmount怎么用?PHP Order::getDiscountAmount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order
的用法示例。
在下文中一共展示了Order::getDiscountAmount方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startTransaction
public function startTransaction(Order $order, UrlInterface $url)
{
$config = new Config($this->_scopeConfig);
$config->configureSDK();
$additionalData = $order->getPayment()->getAdditionalInformation();
$bankId = null;
if (isset($additionalData['bank_id'])) {
$bankId = $additionalData['bank_id'];
}
$total = $order->getGrandTotal();
$items = $order->getAllVisibleItems();
$orderId = $order->getIncrementId();
$quoteId = $order->getQuoteId();
$currency = $order->getOrderCurrencyCode();
$returnUrl = $url->getUrl('paynl/checkout/finish/');
$exchangeUrl = $url->getUrl('paynl/checkout/exchange/');
$paymentOptionId = $this->getPaymentOptionId();
$arrBillingAddress = $order->getBillingAddress();
if ($arrBillingAddress) {
$arrBillingAddress = $arrBillingAddress->toArray();
$enduser = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname'], 'phoneNumber' => $arrBillingAddress['telephone'], 'emailAddress' => $arrBillingAddress['email']);
$invoiceAddress = array('initials' => substr($arrBillingAddress['firstname'], 0, 1), 'lastName' => $arrBillingAddress['lastname']);
$arrAddress = \Paynl\Helper::splitAddress($arrBillingAddress['street']);
$invoiceAddress['streetName'] = $arrAddress[0];
$invoiceAddress['houseNumber'] = $arrAddress[1];
$invoiceAddress['zipCode'] = $arrBillingAddress['postcode'];
$invoiceAddress['city'] = $arrBillingAddress['city'];
$invoiceAddress['country'] = $arrBillingAddress['country_id'];
}
$arrShippingAddress = $order->getShippingAddress();
if ($arrShippingAddress) {
$arrShippingAddress = $arrShippingAddress->toArray();
$shippingAddress = array('initials' => substr($arrShippingAddress['firstname'], 0, 1), 'lastName' => $arrShippingAddress['lastname']);
$arrAddress2 = \Paynl\Helper::splitAddress($arrShippingAddress['street']);
$shippingAddress['streetName'] = $arrAddress2[0];
$shippingAddress['houseNumber'] = $arrAddress2[1];
$shippingAddress['zipCode'] = $arrShippingAddress['postcode'];
$shippingAddress['city'] = $arrShippingAddress['city'];
$shippingAddress['country'] = $arrShippingAddress['country_id'];
}
$data = array('amount' => $total, 'returnUrl' => $returnUrl, 'paymentMethod' => $paymentOptionId, 'bank' => $bankId, 'description' => $orderId, 'extra1' => $orderId, 'extra2' => $quoteId, 'exchangeUrl' => $exchangeUrl, 'currency' => $currency);
if (isset($shippingAddress)) {
$data['address'] = $shippingAddress;
}
if (isset($invoiceAddress)) {
$data['invoiceAddress'] = $invoiceAddress;
}
if (isset($enduser)) {
$data['enduser'] = $enduser;
}
$arrProducts = array();
foreach ($items as $item) {
$arrItem = $item->toArray();
if ($arrItem['price_incl_tax'] != null) {
// taxamount is not valid, because on discount it returns the taxamount after discount
$taxAmount = $arrItem['price_incl_tax'] - $arrItem['price'];
$product = array('id' => $arrItem['product_id'], 'name' => $arrItem['name'], 'price' => $arrItem['price_incl_tax'], 'qty' => $arrItem['qty_ordered'], 'tax' => $taxAmount);
}
$arrProducts[] = $product;
}
//shipping
$shippingCost = $order->getShippingInclTax();
$shippingTax = $order->getShippingTaxAmount();
$shippingDescription = $order->getShippingDescription();
$arrProducts[] = array('id' => 'shipping', 'name' => $shippingDescription, 'price' => $shippingCost, 'qty' => 1, 'tax' => $shippingTax);
// kortingen
$discount = $order->getDiscountAmount();
$discountDescription = $order->getDiscountDescription();
if ($discount != 0) {
$arrProducts[] = array('id' => 'discount', 'name' => $discountDescription, 'price' => $discount, 'qty' => 1, 'tax' => $order->getDiscountTaxCompensationAmount() * -1);
}
$data['products'] = $arrProducts;
if ($config->isTestMode()) {
$data['testmode'] = 1;
}
$data['ipaddress'] = $order->getRemoteIp();
$transaction = \Paynl\Transaction::start($data);
return $transaction->getRedirectUrl();
}
示例2: build
/**
* Loads the order info from a Magento order model.
*
* @param Order $order the order model.
* @return \NostoOrder
*/
public function build(Order $order)
{
$nostoOrder = new \NostoOrder();
try {
$nostoCurrency = new NostoCurrencyCode($order->getOrderCurrencyCode());
$nostoOrder->setOrderNumber($order->getId());
$nostoOrder->setExternalRef($order->getRealOrderId());
$nostoOrder->setCreatedDate(new NostoDate(strtotime($order->getCreatedAt())));
$nostoOrder->setPaymentProvider(new NostoOrderPaymentProvider($order->getPayment()->getMethod()));
if ($order->getStatus()) {
$nostoStatus = new NostoOrderStatus();
$nostoStatus->setCode($order->getStatus());
$nostoStatus->setLabel($order->getStatusLabel());
$nostoOrder->setStatus($nostoStatus);
}
foreach ($order->getAllStatusHistory() as $item) {
if ($item->getStatus()) {
$nostoStatus = new NostoOrderStatus();
$nostoStatus->setCode($item->getStatus());
$nostoStatus->setLabel($item->getStatusLabel());
$nostoStatus->setCreatedAt(new NostoDate(strtotime($item->getCreatedAt())));
$nostoOrder->addHistoryStatus($nostoStatus);
}
}
// Set the buyer information
$nostoBuyer = new NostoOrderBuyer();
$nostoBuyer->setFirstName($order->getCustomerFirstname());
$nostoBuyer->setLastName($order->getCustomerLastname());
$nostoBuyer->setEmail($order->getCustomerEmail());
$nostoOrder->setBuyer($nostoBuyer);
// Add each ordered item as a line item
/** @var Item $item */
foreach ($order->getAllVisibleItems() as $item) {
$nostoItem = new NostoOrderItem();
$nostoItem->setItemId((int) $this->buildItemProductId($item));
$nostoItem->setQuantity((int) $item->getQtyOrdered());
$nostoItem->setName($this->buildItemName($item));
try {
$nostoItem->setUnitPrice(new NostoPrice($this->_priceHelper->getItemFinalPriceInclTax($item)));
} catch (\NostoInvalidArgumentException $E) {
$nostoItem->setUnitPrice(new NostoPrice(0));
}
$nostoItem->setCurrency($nostoCurrency);
$nostoOrder->addItem($nostoItem);
}
// Add discounts as a pseudo line item
if (($discount = $order->getDiscountAmount()) < 0) {
$nostoItem = new NostoOrderItem();
$nostoItem->setItemId(-1);
$nostoItem->setQuantity(1);
$nostoItem->setName($this->buildDiscountRuleDescription($order));
$nostoItem->setUnitPrice(new NostoPrice($discount));
$nostoItem->setCurrency($nostoCurrency);
$nostoOrder->addItem($nostoItem);
}
// Add shipping and handling as a pseudo line item
if (($shippingInclTax = $order->getShippingInclTax()) > 0) {
$nostoItem = new NostoOrderItem();
$nostoItem->setItemId(-1);
$nostoItem->setQuantity(1);
$nostoItem->setName('Shipping and handling');
$nostoItem->setUnitPrice(new NostoPrice($shippingInclTax));
$nostoItem->setCurrency($nostoCurrency);
$nostoOrder->addItem($nostoItem);
}
} catch (Exception $e) {
$this->_logger->error($e, ['exception' => $e]);
}
return $nostoOrder;
}
示例3: _getReceiptOrderLines
/**
* @param \Magento\Sales\Model\Order $order
* @return string
*/
protected function _getReceiptOrderLines(\Magento\Sales\Model\Order $order)
{
$myReceiptOrderLines = "";
$currency = $order->getOrderCurrencyCode();
$formattedAmountValue = $this->_currencyFactory->create()->format($order->getGrandTotal(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$taxAmount = $order->getTaxAmount();
$formattedTaxAmount = $this->_currencyFactory->create()->format($taxAmount, ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$myReceiptOrderLines .= "---||C\n" . "====== YOUR ORDER DETAILS ======||CB\n" . "---||C\n" . " No. Description |Piece Subtotal|\n";
foreach ($order->getItemsCollection() as $item) {
//skip dummies
if ($item->isDummy()) {
continue;
}
$singlePriceFormat = $this->_currencyFactory->create()->format($item->getPriceInclTax(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$itemAmount = $item->getPriceInclTax() * (int) $item->getQtyOrdered();
$itemAmountFormat = $this->_currencyFactory->create()->format($itemAmount, ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$myReceiptOrderLines .= " " . (int) $item->getQtyOrdered() . " " . trim(substr($item->getName(), 0, 25)) . "| " . $currency . " " . $singlePriceFormat . " " . $currency . " " . $itemAmountFormat . "|\n";
}
//discount cost
if ($order->getDiscountAmount() > 0 || $order->getDiscountAmount() < 0) {
$discountAmountFormat = $this->_currencyFactory->create()->format($order->getDiscountAmount(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$myReceiptOrderLines .= " " . 1 . " " . $this->__('Total Discount') . "| " . $currency . " " . $discountAmountFormat . "|\n";
}
//shipping cost
if ($order->getShippingAmount() > 0 || $order->getShippingTaxAmount() > 0) {
$shippingAmountFormat = $this->_currencyFactory->create()->format($order->getShippingAmount(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$myReceiptOrderLines .= " " . 1 . " " . $order->getShippingDescription() . "| " . $currency . " " . $shippingAmountFormat . "|\n";
}
if ($order->getPaymentFeeAmount() > 0) {
$paymentFeeAmount = $this->_currencyFactory->create()->format($order->getPaymentFeeAmount(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
$myReceiptOrderLines .= " " . 1 . " " . $this->__('Payment Fee') . "| " . $currency . " " . $paymentFeeAmount . "|\n";
}
$myReceiptOrderLines .= "|--------|\n" . "|Order Total: " . $currency . " " . $formattedAmountValue . "|B\n" . "|Tax: " . $currency . " " . $formattedTaxAmount . "|B\n" . "||C\n";
/*
* New header for card details section!
* Default location is After Header so simply add to Order Details as separator
*/
$myReceiptOrderLines .= "---||C\n" . "====== YOUR PAYMENT DETAILS ======||CB\n" . "---||C\n";
return $myReceiptOrderLines;
}