Skip to content

[Reorder] #30686 - Allow developers to filter order items for reorder #30687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions app/code/Magento/Sales/Helper/Reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Sales module base helper
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class Reorder extends \Magento\Framework\App\Helper\AbstractHelper
{
Expand Down Expand Up @@ -41,9 +43,11 @@ public function __construct(
}

/**
* Is reorder allowed ?
*
* @return bool
*/
public function isAllow()
public function isAllow(): bool
{
return $this->isAllowed();
}
Expand All @@ -54,7 +58,7 @@ public function isAllow()
* @param \Magento\Store\Model\Store|int|null $store
* @return bool
*/
public function isAllowed($store = null)
public function isAllowed($store = null): bool
{
if ($this->scopeConfig->getValue(
self::XML_PATH_SALES_REORDER_ALLOW,
Expand All @@ -72,16 +76,30 @@ public function isAllowed($store = null)
* @param int $orderId
* @return bool
*/
public function canReorder($orderId)
public function canReorder($orderId): bool
{
$order = $this->orderRepository->get($orderId);
if (!$this->isAllowed($order->getStore())) {
return false;
}
if ($this->customerSession->isLoggedIn()) {
return $order->canReorder();
return (bool) $order->canReorder();
} else {
return true;
}
}

/**
* Check is it possible to reorder one item.
*
* @param \Magento\Sales\Model\Order\Item $item
* @param \Magento\Catalog\Model\Product $product
* @return bool
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function canReorderItem($item, $product): bool
{
return true;
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Sales/Model/Reorder/Reorder.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ private function addItemsToCart(Quote $cart, ItemCollection $orderItems, string
}
$product = $products[$productId];
foreach ($orderItems as $orderItem) {
if (!$this->reorderHelper->canReorderItem($orderItem, $product)) {
continue;
}
$this->addItemToCart($orderItem, $cart, clone $product);
}
}
Expand Down