本文整理汇总了PHP中Magento\Sales\Model\Order::getAllItems方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::getAllItems方法的具体用法?PHP Order::getAllItems怎么用?PHP Order::getAllItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Sales\Model\Order
的用法示例。
在下文中一共展示了Order::getAllItems方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAllItems
/**
* {@inheritdoc}
*/
public function getAllItems()
{
$resultItems = [];
foreach ($this->_salesModel->getAllItems() as $item) {
$resultItems[] = new \Magento\Framework\DataObject(['parent_item' => $item->getParentItem(), 'name' => $item->getName(), 'qty' => (int) $item->getQtyOrdered(), 'price' => (double) $item->getBasePrice(), 'original_item' => $item]);
}
return $resultItems;
}
示例2: prepareCreditmemo
/**
* Prepare order creditmemo based on order items and requested params
*
* @param array $data
* @return \Magento\Sales\Model\Order\Creditmemo
*/
public function prepareCreditmemo($data = [])
{
$totalQty = 0;
$creditmemo = $this->_convertor->toCreditmemo($this->_order);
$qtys = isset($data['qtys']) ? $data['qtys'] : [];
foreach ($this->_order->getAllItems() as $orderItem) {
if (!$this->_canRefundItem($orderItem, $qtys)) {
continue;
}
$item = $this->_convertor->itemToCreditmemoItem($orderItem);
if ($orderItem->isDummy()) {
$qty = 1;
$orderItem->setLockedDoShip(true);
} else {
if (isset($qtys[$orderItem->getId()])) {
$qty = (double) $qtys[$orderItem->getId()];
} elseif (!count($qtys)) {
$qty = $orderItem->getQtyToRefund();
} else {
continue;
}
}
$totalQty += $qty;
$item->setQty($qty);
$creditmemo->addItem($item);
}
$creditmemo->setTotalQty($totalQty);
$this->_initCreditmemoData($creditmemo, $data);
$creditmemo->collectTotals();
return $creditmemo;
}
示例3: getKhipuRequest
/**
* @param Order $order
* @return array
*/
public function getKhipuRequest(Order $order)
{
$token = substr(md5(rand()), 0, 32);
$payment = $order->getPayment();
$payment->setAdditionalInformation('khipu_order_token', $token);
$payment->save();
$description = array();
foreach ($order->getAllItems() as $item) {
$description[] = number_format($item->getQtyOrdered(), 0) . ' × ' . $item->getName();
}
$configuration = new \Khipu\Configuration();
$configuration->setSecret($this->getConfigData('merchant_secret'));
$configuration->setReceiverId($this->getConfigData('merchant_id'));
$configuration->setPlatform('magento2-khipu', Payment::KHIPU_MAGENTO_VERSION);
$client = new \Khipu\ApiClient($configuration);
$payments = new \Khipu\Client\PaymentsApi($client);
try {
$createPaymentResponse = $payments->paymentsPost($this->storeManager->getWebsite()->getName() . ' Carro #' . $order->getIncrementId(), $order->getOrderCurrencyCode(), number_format($order->getGrandTotal(), $this->getDecimalPlaces($order->getOrderCurrencyCode()), '.', ''), $payment->getAdditionalInformation('khipu_order_token'), null, join($description, ', '), null, $this->urlBuilder->getUrl('checkout/onepage/success'), $this->urlBuilder->getUrl('checkout/onepage/failure'), null, $this->urlBuilder->getUrl('khipu/payment/callback') . '?order_id=' . $order->getIncrementId(), '1.3', null, null, null, null, null, null, null, null);
} catch (\Khipu\ApiException $exception) {
$error = $exception->getResponseObject();
$msg = "Error de comunicación con khipu.\n";
$msg .= "Código: " . $error->getStatus() . "\n";
$msg .= "Mensaje: " . $error->getMessage() . "\n";
if (method_exists($error, 'getErrors')) {
$msg .= "Errores:";
foreach ($error->getErrors() as $errorItem) {
$msg .= "\n" . $errorItem->getField() . ": " . $errorItem->getMessage();
}
}
return array('reason' => $msg, 'status' => false);
}
return array('status' => true, 'payment_url' => $createPaymentResponse->getPaymentUrl());
}
示例4: getCoinGateRequest
/**
* @param Order $order
* @return array
*/
public function getCoinGateRequest(Order $order)
{
$token = substr(md5(rand()), 0, 32);
$payment = $order->getPayment();
$payment->setAdditionalInformation('coingate_order_token', $token);
$payment->save();
$description = array();
foreach ($order->getAllItems() as $item) {
$description[] = number_format($item->getQtyOrdered(), 0) . ' × ' . $item->getName();
}
$params = array('order_id' => $order->getIncrementId(), 'price' => number_format($order->getGrandTotal(), 2, '.', ''), 'currency' => $order->getOrderCurrencyCode(), 'receive_currency' => $this->getConfigData('receive_currency'), 'callback_url' => $this->urlBuilder->getUrl('coingate/payment/callback') . '?token=' . $payment->getAdditionalInformation('coingate_order_token'), 'cancel_url' => $this->urlBuilder->getUrl('checkout/onepage/failure'), 'success_url' => $this->urlBuilder->getUrl('checkout/onepage/success'), 'title' => $this->storeManager->getWebsite()->getName(), 'description' => join($description, ', '));
$this->coingate->createOrder($params);
if ($this->coingate->success) {
return array('status' => true, 'payment_url' => $this->coingate->response['payment_url']);
} else {
return array('status' => false);
}
}
示例5: prepareItems
/**
* Adds items to the shipment.
*
* @param \Magento\Sales\Api\Data\ShipmentInterface $shipment
* @param \Magento\Sales\Model\Order $order
* @param array $items
* @return \Magento\Sales\Api\Data\ShipmentInterface
*/
protected function prepareItems(\Magento\Sales\Api\Data\ShipmentInterface $shipment, \Magento\Sales\Model\Order $order, array $items = [])
{
$totalQty = 0;
foreach ($order->getAllItems() as $orderItem) {
if (!$this->canShipItem($orderItem, $items)) {
continue;
}
/** @var \Magento\Sales\Model\Order\Shipment\Item $item */
$item = $this->converter->itemToShipmentItem($orderItem);
if ($orderItem->isDummy(true)) {
$qty = 0;
if (isset($items[$orderItem->getParentItemId()])) {
$productOptions = $orderItem->getProductOptions();
if (isset($productOptions['bundle_selection_attributes'])) {
$bundleSelectionAttributes = unserialize($productOptions['bundle_selection_attributes']);
if ($bundleSelectionAttributes) {
$qty = $bundleSelectionAttributes['qty'] * $items[$orderItem->getParentItemId()];
$qty = min($qty, $orderItem->getSimpleQtyToShip());
$item->setQty($qty);
$shipment->addItem($item);
continue;
} else {
$qty = 1;
}
}
} else {
$qty = 1;
}
} else {
if (isset($items[$orderItem->getId()])) {
$qty = min($items[$orderItem->getId()], $orderItem->getQtyToShip());
} elseif (!count($items)) {
$qty = $orderItem->getQtyToShip();
} else {
continue;
}
}
$totalQty += $qty;
$item->setQty($qty);
$shipment->addItem($item);
}
return $shipment->setTotalQty($totalQty);
}
示例6: calculateItems
/**
* Process items dependency for new order, returns qty of affected items;
*
* @param \Magento\Sales\Model\Order $object
* @return int
*/
protected function calculateItems(\Magento\Sales\Model\Order $object)
{
$itemsCount = 0;
if (!$object->getId()) {
foreach ($object->getAllItems() as $item) {
/** @var \Magento\Sales\Model\Order\Item $item */
$parent = $item->getQuoteParentItemId();
if ($parent && !$item->getParentItem()) {
$item->setParentItem($object->getItemByQuoteItemId($parent));
}
$childItems = $item->getChildrenItems();
if (empty($childItems)) {
$itemsCount++;
}
}
}
return $itemsCount;
}
示例7: makePurchase
/**
* @param $order Order
* @return Purchase
*/
protected function makePurchase(Order $order)
{
// Get all of the purchased products
$items = $order->getAllItems();
$purchase = SignifydModel::Make("\\Signifyd\\Models\\Purchase");
$purchase->orderChannel = "WEB";
$purchase->products = array();
foreach ($items as $item) {
$purchase->products[] = $this->makeProduct($item);
}
$purchase->totalPrice = $order->getGrandTotal();
$purchase->currency = $order->getOrderCurrencyCode();
$purchase->orderId = $order->getIncrementId();
$purchase->paymentGateway = $order->getPayment()->getMethod();
$purchase->shippingPrice = floatval($order->getShippingAmount());
$purchase->avsResponseCode = $order->getPayment()->getCcAvsStatus();
$purchase->cvvResponseCode = $order->getPayment()->getCcSecureVerify();
$purchase->createdAt = date('c', strtotime($order->getCreatedAt()));
$purchase->browserIpAddress = $this->getIPAddress($order);
return $purchase;
}
示例8: _getOrderDescription
/**
* Get formatted order description
*
* @param \Magento\Sales\Model\Order $order
* @return string
*/
protected function _getOrderDescription($order)
{
$invoiceDesc = '';
foreach ($order->getAllItems() as $item) {
if ($item->getParentItem()) {
continue;
}
//COM filed can only handle max 100
if ($this->string->strlen($invoiceDesc . $item->getName()) > 100) {
break;
}
$invoiceDesc .= $item->getName() . ', ';
}
return $this->string->substr($invoiceDesc, 0, -2);
}