Skip to content

Commit

Permalink
Merge pull request #103 from IrinaZhadzinets/issue-5087
Browse files Browse the repository at this point in the history
#5087 - Remove error about out of stock item in cart
  • Loading branch information
carinadues authored Aug 4, 2022
2 parents 3a368ed + 139f063 commit 53718f1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/Model/Cart/GetCartForUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* ScandiPWA - Progressive Web App for Magento
*
* Copyright © Scandiweb, Inc. All rights reserved.
* See LICENSE for license details.
*
* @license OSL-3.0 (Open Software License ("OSL") v. 3.0)
* @package scandipwa/quote-graphql
* @link https://github.com/scandipwa/quote-graphql
*/

declare(strict_types=1);

namespace ScandiPWA\QuoteGraphQl\Model\Cart;

use Magento\Quote\Model\Quote;
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser as SourceGetCartForUser;

/**
* Class GetCartForUser
* @package ScandiPWA\QuoteGraphQl\Model\Cart
*/
class GetCartForUser extends SourceGetCartForUser
{
/**
* Type of error
*/
public const ERROR_TYPE = 'stock';

/**
* Message for out of stock item in cart
*/
public const ERROR_MESSAGE = 'Some of the products are out of stock.';

/**
* Get cart for user
*
* @param string $cartHash
* @param int|null $customerId
* @param int $storeId
* @return Quote
*/
public function execute(string $cartHash, ?int $customerId, int $storeId): Quote
{
$cart = parent::execute($cartHash, $customerId, $storeId);

// For magento, this error is used for notification.
// But for PWA, this error prevents working with cart data,
// and out_of_stock status is processed based on product fields, not stock error
// Therefore, the error is removed if it concerns 'Out of stock item in cart'
$cart->removeMessageByText(self::ERROR_TYPE, self::ERROR_MESSAGE);

return $cart;
}
}
2 changes: 2 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,7 @@
type="ScandiPWA\QuoteGraphQl\Model\Resolver\CartItems"/>
<preference for="Magento\QuoteGraphQl\Model\Resolver\ShippingAddress\SelectedShippingMethod"
type="ScandiPWA\QuoteGraphQl\Model\Resolver\ShippingAddress\SelectedShippingMethod"/>
<preference for="Magento\QuoteGraphQl\Model\Cart\GetCartForUser"
type="ScandiPWA\QuoteGraphQl\Model\Cart\GetCartForUser"/>
</config>

0 comments on commit 53718f1

Please sign in to comment.