作者:whoopl
项目:magento2-testin
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param array $response
* @return void
*/
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
{
$this->assertEquals($orderItem->getId(), $response['item_id']);
$this->assertEquals($orderItem->getOrderId(), $response['order_id']);
$this->assertEquals($orderItem->getProductId(), $response['product_id']);
$this->assertEquals($orderItem->getProductType(), $response['product_type']);
$this->assertEquals($orderItem->getBasePrice(), $response['base_price']);
$this->assertEquals($orderItem->getRowTotal(), $response['row_total']);
}
作者:pradeep-wagent
项目:magento
/**
* Get product id
*
* @param \Magento\Sales\Model\Order\Admin\Item $subject
* @param callable $proceed
* @param \Magento\Sales\Model\Order\Item $item
*
* @return int
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundGetProductId(\Magento\Sales\Model\Order\Admin\Item $subject, \Closure $proceed, \Magento\Sales\Model\Order\Item $item)
{
if ($item->getProductType() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
$productOptions = $item->getProductOptions();
$product = $this->productFactory->create();
return $product->getIdBySku($productOptions['simple_sku']);
}
return $proceed($item);
}
作者:whoopl
项目:magento2-testin
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param array $response
* @return void
*/
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
{
$expected = $orderItem->getBuyRequest()->getLinks();
$this->assertArrayHasKey('product_option', $response);
$this->assertArrayHasKey('extension_attributes', $response['product_option']);
$this->assertArrayHasKey('downloadable_option', $response['product_option']['extension_attributes']);
$actualOptions = $response['product_option']['extension_attributes']['downloadable_option'];
$this->assertArrayHasKey('downloadable_links', $actualOptions);
$this->assertEquals($expected, $actualOptions['downloadable_links']);
}
作者:andrewhowdenco
项目:m2onk8
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param array $response
* @return void
*/
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
{
$expected = $orderItem->getBuyRequest()->getSuperAttribute();
$this->assertArrayHasKey('product_option', $response);
$this->assertArrayHasKey('extension_attributes', $response['product_option']);
$this->assertArrayHasKey('configurable_item_options', $response['product_option']['extension_attributes']);
$actualOptions = $response['product_option']['extension_attributes']['configurable_item_options'];
$this->assertTrue(is_array($actualOptions));
$this->assertTrue(is_array($actualOptions[0]));
$this->assertArrayHasKey('option_id', $actualOptions[0]);
$this->assertArrayHasKey('option_value', $actualOptions[0]);
$this->assertEquals(key($expected), $actualOptions[0]['option_id']);
$this->assertEquals(current($expected), $actualOptions[0]['option_value']);
}
作者:andrewhowdenco
项目:m2onk8
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param array $response
* @return void
*/
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
{
$bundleOption = $orderItem->getBuyRequest()->getBundleOption();
$bundleOptionQty = $orderItem->getBuyRequest()->getBundleOptionQty();
$this->assertArrayHasKey('product_option', $response);
$this->assertArrayHasKey('extension_attributes', $response['product_option']);
$this->assertArrayHasKey('bundle_options', $response['product_option']['extension_attributes']);
$actualOptions = $response['product_option']['extension_attributes']['bundle_options'];
$this->assertEquals(array_keys($bundleOption), array_column($actualOptions, 'option_id'));
$this->assertEquals($bundleOptionQty, array_column($actualOptions, 'option_qty', 'option_id'));
foreach ($actualOptions as $option) {
$expectedSelections = is_array($bundleOption[$option['option_id']]) ? $bundleOption[$option['option_id']] : [$bundleOption[$option['option_id']]];
$this->assertEquals($expectedSelections, $option['option_selections']);
}
}
作者:andrewhowdenco
项目:m2onk8
/**
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param array $response
* @return void
*/
protected function assertOrderItem(\Magento\Sales\Model\Order\Item $orderItem, array $response)
{
$expected = $orderItem->getBuyRequest()->getOptions();
$this->assertArrayHasKey('product_option', $response);
$this->assertArrayHasKey('extension_attributes', $response['product_option']);
$this->assertArrayHasKey('custom_options', $response['product_option']['extension_attributes']);
$actualOptions = $response['product_option']['extension_attributes']['custom_options'];
$expectedOptions = [];
foreach ($expected as $optionId => $optionValue) {
if (is_array($optionValue)) {
$optionValue = implode(',', $optionValue);
}
$expectedOptions[] = ['option_id' => $optionId, 'option_value' => $optionValue];
}
$this->assertEquals($expectedOptions, $actualOptions);
}
作者:nja7
项目:magento
public function testSave()
{
$this->orderMock->expects($this->exactly(3))->method('getId')->willReturn(null);
$this->orderItemMock->expects($this->once())->method('getChildrenItems')->willReturn([]);
$this->orderItemMock->expects($this->once())->method('getQuoteParentItemId')->willReturn(null);
$this->orderMock->expects($this->once())->method('setTotalItemCount')->with(1);
$this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
$this->orderMock->expects($this->once())->method('getAllItems')->willReturn([$this->orderItemMock]);
$this->orderMock->expects($this->once())->method('validateBeforeSave')->willReturnSelf();
$this->orderMock->expects($this->once())->method('beforeSave')->willReturnSelf();
$this->orderMock->expects($this->once())->method('isSaveAllowed')->willReturn(true);
$this->orderMock->expects($this->once())->method('getEntityType')->willReturn('order');
$this->orderMock->expects($this->exactly(2))->method('getStore')->willReturn($this->storeMock);
$this->storeMock->expects($this->exactly(2))->method('getGroup')->willReturn($this->storeGroupMock);
$this->storeMock->expects($this->once())->method('getWebsite')->willReturn($this->websiteMock);
$this->storeGroupMock->expects($this->once())->method('getDefaultStoreId')->willReturn(1);
$this->salesSequenceManagerMock->expects($this->once())->method('getSequence')->with('order', 1)->willReturn($this->salesSequenceMock);
$this->salesSequenceMock->expects($this->once())->method('getNextValue')->willReturn('10000001');
$this->orderMock->expects($this->once())->method('setIncrementId')->with('10000001')->willReturnSelf();
$this->orderMock->expects($this->once())->method('getIncrementId')->willReturn(null);
$this->orderMock->expects($this->once())->method('getData')->willReturn(['increment_id' => '10000001']);
$this->objectRelationProcessorMock->expects($this->once())->method('validateDataIntegrity')->with(null, ['increment_id' => '10000001']);
$this->relationCompositeMock->expects($this->once())->method('processRelations')->with($this->orderMock);
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
$this->adapterMock->expects($this->any())->method('quoteInto');
$this->adapterMock->expects($this->any())->method('describeTable')->will($this->returnValue([]));
$this->adapterMock->expects($this->any())->method('update');
$this->adapterMock->expects($this->any())->method('lastInsertId');
$this->orderMock->expects($this->any())->method('getId')->will($this->returnValue(1));
$this->entitySnapshotMock->expects($this->once())->method('isModified')->with($this->orderMock)->will($this->returnValue(true));
$this->resource->save($this->orderMock);
}
作者:tingyee
项目:magento
public function testGetOriginalPrice()
{
$price = 9.99;
$this->model->setPrice($price);
$this->assertEquals($price, $this->model->getOriginalPrice());
$originalPrice = 5.55;
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
$this->assertEquals($originalPrice, $this->model->getOriginalPrice());
}
作者:pradeep-wagent
项目:magento
public function testCollect()
{
$this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]);
$this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock);
$this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false);
$this->creditmemoItemMock->expects($this->once())->method('calcRowTotal')->willReturnSelf();
$this->creditmemoItemMock->expects($this->once())->method('getRowTotal')->willReturn(1);
$this->creditmemoItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(1);
$this->creditmemoItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
$this->creditmemoItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('setSubtotal')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('setBaseSubtotal')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('setSubtotalInclTax')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('setBaseSubtotalInclTax')->with(1)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('setGrandTotal')->with(2)->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('setBaseGrandTotal')->with(2)->willReturnSelf();
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
}
作者:pradeep-wagent
项目:magento
public function testProcessRelation()
{
$this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->orderMock)->willReturnSelf();
$this->addressHandlerMock->expects($this->once())->method('process')->with($this->orderMock)->willReturnSelf();
$this->orderMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->orderItemMock]);
$this->orderMock->expects($this->exactly(3))->method('getId')->willReturn('order-id-value');
$this->orderItemMock->expects($this->once())->method('setOrderId')->with('order-id-value')->willReturnSelf();
$this->orderItemMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
$this->orderItemRepositoryMock->expects($this->once())->method('save')->with($this->orderItemMock)->willReturnSelf();
$this->orderMock->expects($this->exactly(2))->method('getPayment')->willReturn($this->orderPaymentMock);
$this->orderPaymentMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
$this->orderPaymentMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
$this->orderPaymentResourceMock->expects($this->once())->method('save')->with($this->orderPaymentMock)->willReturnSelf();
$this->orderMock->expects($this->exactly(2))->method('getStatusHistories')->willReturn([$this->orderStatusHistoryMock]);
$this->orderStatusHistoryMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
$this->orderStatusHistoryMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
$this->statusHistoryResource->expects($this->once())->method('save')->with($this->orderStatusHistoryMock)->willReturnSelf();
$this->orderMock->expects($this->exactly(2))->method('getRelatedObjects')->willReturn([$this->orderInvoiceMock]);
$this->orderInvoiceMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
$this->orderInvoiceMock->expects($this->once())->method('save')->willReturnSelf();
$this->relationProcessor->processRelation($this->orderMock);
}
作者:smile-s
项目:elasticsuit
/**
* Retrieve tracking variables for an order item
*
* @param \Magento\Sales\Model\Order\Item $item The order item
*
* @return array
*/
private function getOrderItemVariables($item)
{
$variables = [];
if (!$item->isDummy()) {
$itemId = $item->getId();
$prefix = "order.items.{$itemId}";
$variables[$prefix . '.sku'] = $item->getSku();
$variables[$prefix . '.product_id'] = $item->getProductId();
$variables[$prefix . '.qty'] = $item->getQtyOrdered();
$variables[$prefix . '.price'] = $item->getBasePrice();
$variables[$prefix . '.row_total'] = $item->getRowTotal();
$variables[$prefix . '.label'] = $item->getName();
$variables[$prefix . '.salesrules'] = $item->getAppliedRuleIds();
if ($product = $item->getProduct()) {
$categoriesId = $product->getCategoryIds();
if (count($categoriesId)) {
$variables[$prefix . '.category_ids'] = implode(",", $categoriesId);
}
}
}
return $variables;
}
作者:shabbirvividad
项目:magento
public function testCalcRowTotal()
{
$this->item->setData(['order_item_id' => 1, 'qty' => 2]);
$this->item->setInvoice($this->invoiceMock);
$this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
$this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock);
$this->orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getRowTotal')->willReturn(2);
$this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(2);
$this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(0);
$this->invoiceMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[2, 'regular', false, 2], [2, 'base', false, 2], [2, 'including', false, 2], [2, 'including_base', false, 2]]);
$this->assertEquals($this->item->calcRowTotal(), $this->item);
}
作者:shabbirvividad
项目:magento
public function testCollect()
{
$this->creditmemoMock->expects($this->exactly(2))->method('setDiscountAmount')->willReturnSelf();
$this->creditmemoMock->expects($this->exactly(2))->method('setBaseDiscountAmount')->willReturnSelf();
$this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
$this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn(1);
$this->orderMock->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn(1);
$this->orderMock->expects($this->exactly(2))->method('getBaseShippingAmount')->willReturn(1);
$this->orderMock->expects($this->once())->method('getShippingAmount')->willReturn(1);
$this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]);
$this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock);
$this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false);
$this->orderItemMock->expects($this->once())->method('getDiscountInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getBaseDiscountInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getDiscountRefunded')->willReturn(1);
$this->orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(0);
$this->creditmemoItemMock->expects($this->once())->method('isLast')->willReturn(false);
$this->creditmemoItemMock->expects($this->atLeastOnce())->method('getQty')->willReturn(1);
$this->creditmemoItemMock->expects($this->exactly(1))->method('setDiscountAmount')->willReturnSelf();
$this->creditmemoItemMock->expects($this->exactly(1))->method('setBaseDiscountAmount')->willReturnSelf();
$this->creditmemoMock->expects($this->exactly(2))->method('roundPrice')->willReturnMap([[1, 'regular', true, 1], [1, 'base', true, 1]]);
$this->assertEquals($this->total, $this->total->collect($this->creditmemoMock));
}
作者:zhangjiacha
项目:magento
/**
* @param \Magento\Sales\Model\Order\Item $item
* @return $this
*/
public function addItem(\Magento\Sales\Model\Order\Item $item)
{
$item->setOrder($this);
if (!$item->getId()) {
$this->getItemsCollection()->addItem($item);
}
return $this;
}
作者:whoopl
项目:magento2-testin
/**
* Initialize creation data from existing order Item
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @param int $qty
* @return \Magento\Quote\Model\Quote\Item|string|$this
*/
public function initFromOrderItem(\Magento\Sales\Model\Order\Item $orderItem, $qty = null)
{
if (!$orderItem->getId()) {
return $this;
}
$product = $this->_objectManager->create('Magento\\Catalog\\Model\\Product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId());
if ($product->getId()) {
$product->setSkipCheckRequiredOption(true);
$buyRequest = $orderItem->getBuyRequest();
if (is_numeric($qty)) {
$buyRequest->setQty($qty);
}
$item = $this->getQuote()->addProduct($product, $buyRequest);
if (is_string($item)) {
return $item;
}
if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) {
$item->addOption(new \Magento\Framework\DataObject(['product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions)]));
}
$this->_eventManager->dispatch('sales_convert_order_item_to_quote_item', ['order_item' => $orderItem, 'quote_item' => $item]);
return $item;
}
return $this;
}
作者:kidaa3
项目:magento2-platforms
/**
* Calculate base total amount for the item
*
* @param QuoteItem|Item|InvoiceItem|CreditmemoItem $item
* @return mixed
*/
public function getBaseTotalAmount($item)
{
$baseTotalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
return $baseTotalAmount;
}
作者:pradeep-wagent
项目:magento
/**
* Checks if order item can be shipped.
*
* Dummy item can be shipped or with his children or
* with parent item which is included to shipment.
*
* @param \Magento\Sales\Model\Order\Item $item
* @param array $items
* @return bool
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function canShipItem($item, array $items = [])
{
if ($item->getIsVirtual() || $item->getLockedDoShip()) {
return false;
}
if ($item->isDummy(true)) {
if ($item->getHasChildren()) {
if ($item->isShipSeparately()) {
return true;
}
foreach ($item->getChildrenItems() as $child) {
if ($child->getIsVirtual()) {
continue;
}
if (empty($items)) {
if ($child->getQtyToShip() > 0) {
return true;
}
} else {
if (isset($items[$child->getId()]) && $items[$child->getId()] > 0) {
return true;
}
}
}
return false;
} elseif ($item->getParentItem()) {
$parent = $item->getParentItem();
if (empty($items)) {
return $parent->getQtyToShip() > 0;
} else {
return isset($items[$parent->getId()]) && $items[$parent->getId()] > 0;
}
}
} else {
return $item->getQtyToShip() > 0;
}
}
作者:zhangjiacha
项目:magento
/**
* Return the total amount minus discount
*
* @param OrderItem|InvoiceItem|CreditMemoItem $item
* @return mixed
*/
public function getBaseTotalAmount($item)
{
$totalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $item->getBaseTaxAmount() + $item->getBaseHiddenTaxAmount() + $this->weeeHelper->getBaseRowWeeeTaxInclTax($item);
return $totalAmount;
}
作者:pradeep-wagent
项目:magento
/**
* Check item product availability for reorder
*
* @param \Magento\Sales\Model\Order\Item $orderItem
* @return boolean
*/
protected function isItemAvailableForReorder(\Magento\Sales\Model\Order\Item $orderItem)
{
try {
$stockItem = $this->stockRegistry->getStockItem($orderItem->getProduct()->getId(), $orderItem->getStore()->getWebsiteId());
return $stockItem->getIsInStock();
} catch (\Magento\Framework\Exception\NoSuchEntityException $noEntityException) {
return false;
}
}
作者:kidaa3
项目:magento2-platforms
/**
* Declare order item instance
*
* @param \Magento\Sales\Model\Order\Item $item
* @return $this
*/
public function setOrderItem(\Magento\Sales\Model\Order\Item $item)
{
$this->_orderItem = $item;
$this->setOrderItemId($item->getId());
return $this;
}