本文整理汇总了PHP中Magento\Sales\Model\Order\Item类的典型用法代码示例。如果您正苦于以下问题:PHP Item类的具体用法?PHP Item怎么用?PHP Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertOrderItem
/**
* @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']);
}
示例2: aroundGetProductId
/**
* 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);
}
示例3: assertOrderItem
/**
* @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']);
}
示例4: assertOrderItem
/**
* @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']);
}
示例5: assertOrderItem
/**
* @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']);
}
}
示例6: assertOrderItem
/**
* @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);
}
示例7: testSave
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);
}
示例8: testGetOriginalPrice
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());
}
示例9: testCollect
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));
}
示例10: testProcessRelation
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);
}
示例11: getOrderItemVariables
/**
* 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;
}
示例12: testCalcRowTotal
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);
}
示例13: testCollect
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));
}
示例14: addItem
/**
* @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;
}
示例15: initFromOrderItem
/**
* 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;
}