Skip to content

Commit 08ced37

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-72843' into 2.2-develop-pr72
2 parents 5a722b5 + aa9f06f commit 08ced37

File tree

4 files changed

+154
-5
lines changed

4 files changed

+154
-5
lines changed

app/code/Magento/Sales/Model/Order.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,15 +1400,18 @@ public function getParentItemsRandomCollection($limit = 1)
14001400
}
14011401

14021402
/**
1403-
* Get random items collection with or without related children
1403+
* Get random items collection with or without related children.
14041404
*
14051405
* @param int $limit
14061406
* @param bool $nonChildrenOnly
14071407
* @return ItemCollection
14081408
*/
14091409
protected function _getItemsRandomCollection($limit, $nonChildrenOnly = false)
14101410
{
1411-
$collection = $this->_orderItemCollectionFactory->create()->setOrderFilter($this)->setRandomOrder();
1411+
$collection = $this->_orderItemCollectionFactory->create()
1412+
->setOrderFilter($this)
1413+
->setRandomOrder()
1414+
->setPageSize($limit);
14121415

14131416
if ($nonChildrenOnly) {
14141417
$collection->filterByParent();
@@ -1422,9 +1425,7 @@ protected function _getItemsRandomCollection($limit, $nonChildrenOnly = false)
14221425
$products
14231426
)->setVisibility(
14241427
$this->_productVisibility->getVisibleInSiteIds()
1425-
)->addPriceData()->setPageSize(
1426-
$limit
1427-
)->load();
1428+
)->addPriceData()->load();
14281429

14291430
foreach ($collection as $item) {
14301431
$product = $productsCollection->getItemById($item->getProductId());
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Sales\CustomerData;
8+
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\TestFramework\Helper\Bootstrap;
11+
use PHPUnit\Framework\TestCase;
12+
use Magento\Customer\Model\Session;
13+
14+
/**
15+
* Test for LastOrderedItems.
16+
*
17+
* @magentoAppIsolation enabled
18+
*/
19+
class LastOrderedItemsTest extends TestCase
20+
{
21+
/**
22+
* @var ObjectManagerInterface
23+
*/
24+
private $objectManager;
25+
26+
/**
27+
* @inheritdoc
28+
*/
29+
public function setUp()
30+
{
31+
$this->objectManager = Bootstrap::getObjectManager();
32+
}
33+
34+
/**
35+
* Test to check count in items collection.
36+
*
37+
* @magentoDataFixture Magento/Sales/_files/order_with_customer_and_multiple_order_items.php
38+
*/
39+
public function testDefaultFormatterIsAppliedWhenBasicIntegration()
40+
{
41+
/** @var Session $customerSession */
42+
$customerSession = $this->objectManager->get(Session::class);
43+
$customerSession->loginById(1);
44+
45+
/** @var LastOrderedItems $customerDataSectionSource */
46+
$customerDataSectionSource = $this->objectManager->get(LastOrderedItems::class);
47+
$data = $customerDataSectionSource->getSectionData();
48+
49+
$this->assertEquals(
50+
LastOrderedItems::SIDEBAR_ORDER_LIMIT,
51+
count($data['items']),
52+
'Section items count should not be greater then ' . LastOrderedItems::SIDEBAR_ORDER_LIMIT
53+
);
54+
}
55+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/order_with_multiple_items.php';
8+
require __DIR__ . '/../../../Magento/Customer/_files/customer.php';
9+
10+
$customerIdFromFixture = 1;
11+
/** @var $order \Magento\Sales\Model\Order */
12+
$order->setCustomerId($customerIdFromFixture)->setCustomerIsGuest(false)->save();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require 'order.php';
8+
/** @var \Magento\Catalog\Model\Product $product */
9+
/** @var \Magento\Sales\Model\Order $order */
10+
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
11+
12+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple.php';
13+
$orderItems[] = [
14+
'product_id' => $product->getId(),
15+
'base_price' => 123,
16+
'order_id' => $order->getId(),
17+
'price' => 123,
18+
'row_total' => 126,
19+
'product_type' => 'simple'
20+
];
21+
22+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_duplicated.php';
23+
$orderItems[] = [
24+
'product_id' => $product->getId(),
25+
'base_price' => 123,
26+
'order_id' => $order->getId(),
27+
'price' => 123,
28+
'row_total' => 126,
29+
'product_type' => 'simple'
30+
];
31+
32+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_with_decimal_qty.php';
33+
$orderItems[] = [
34+
'product_id' => $product->getId(),
35+
'base_price' => 123,
36+
'order_id' => $order->getId(),
37+
'price' => 123,
38+
'row_total' => 126,
39+
'product_type' => 'simple'
40+
];
41+
42+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_with_url_key.php';
43+
$orderItems[] = [
44+
'product_id' => $product->getId(),
45+
'base_price' => 123,
46+
'order_id' => $order->getId(),
47+
'price' => 123,
48+
'row_total' => 126,
49+
'product_type' => 'simple'
50+
];
51+
52+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_sku_with_slash.php';
53+
$orderItems[] = [
54+
'product_id' => $product->getId(),
55+
'base_price' => 123,
56+
'order_id' => $order->getId(),
57+
'price' => 123,
58+
'row_total' => 126,
59+
'product_type' => 'simple'
60+
];
61+
62+
require __DIR__ . '/../../../Magento/Catalog/_files/product_simple_xss.php';
63+
$orderItems[] = [
64+
'product_id' => $product->getId(),
65+
'base_price' => 123,
66+
'order_id' => $order->getId(),
67+
'price' => 123,
68+
'row_total' => 126,
69+
'product_type' => 'simple'
70+
];
71+
72+
/** @var array $orderItemData */
73+
foreach ($orderItems as $orderItemData) {
74+
/** @var $orderItem \Magento\Sales\Model\Order\Item */
75+
$orderItem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
76+
\Magento\Sales\Model\Order\Item::class
77+
);
78+
$orderItem
79+
->setData($orderItemData)
80+
->save();
81+
}

0 commit comments

Comments
 (0)