Skip to content
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

WIP GetCartForPaymentQuery #1249

Open
wants to merge 1 commit into
base: prestashop/8.x
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ services:
PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\Query\GetPayPalGetUserIdTokenQuery: 'PrestaShop\Module\PrestashopCheckout\PayPal\OAuth\Query\GetPayPalGetUserIdTokenQueryHandler'
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Command\SavePayPalOrderCommand: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\CommandHandler\SavePayPalOrderCommandHandler'
PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQuery: 'PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Query\GetGooglePayTransactionInfoQueryHandler'
PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQuery: 'PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler'

PrestaShop\Module\PrestashopCheckout\Event\SymfonyEventDispatcherFactory:
class: 'PrestaShop\Module\PrestashopCheckout\Event\SymfonyEventDispatcherFactory'
Expand Down
4 changes: 4 additions & 0 deletions config/query-handlers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,7 @@ services:
public: true
arguments:
- '@PrestaShop\Module\PrestashopCheckout\PayPal\GooglePay\Builder\GooglePayTransactionInfoBuilder'

PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler:
class: 'PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler'
public: true
44 changes: 44 additions & 0 deletions src/Cart/Query/GetCartForPaymentQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\Cart\Query;

use PrestaShop\Module\PrestashopCheckout\Cart\ValueObject\CartId;

class GetCartForPaymentQuery
{
/**
* @var CartId
*/
private $cartId;

public function __construct(CartId $cartId)
{
$this->cartId = $cartId;
}

/**
* @return CartId
*/
public function getCartId()
{
return $this->cartId;
}
}
69 changes: 69 additions & 0 deletions src/Cart/Query/GetCartForPaymentQueryHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\Cart\Query;

use Cart;
use Currency;
use Customer;

class GetCartForPaymentQueryHandler
{
public function handle(GetCartForPaymentQuery $query)
{
$cart = new Cart($query->getCartId()->getValue());
$currency = new Currency($cart->id_currency);
$language = $cart->getAssociatedLanguage();

return new GetCartForPaymentQueryResult($cart, $cart->getProducts());

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.

Check failure on line 35 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Class PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryResult constructor invoked with 2 parameters, 4 required.
}

/**
* @param Cart $cart
*
* @return CartAddress[]
*/
private function getAddresses(Cart $cart)

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.

Check failure on line 43 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Return typehint of method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::getAddresses() has invalid type PrestaShop\Module\PrestashopCheckout\Cart\Query\CartAddress.
{
$customer = new Customer($cart->id_customer);
$cartAddresses = [];

foreach ($customer->getAddresses($cart->getAssociatedLanguage()->getId()) as $data) {
$addressId = (int) $data['id_address'];
$cartAddresses[$addressId] = $this->buildCartAddress($addressId, $cart);

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 50 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().
}

// Add addresses already assigned to cart if absent (in case they are deleted)
if (0 !== (int) $cart->id_address_delivery && !isset($cartAddresses[$cart->id_address_delivery])) {
$cartAddresses[$cart->id_address_delivery] = $this->buildCartAddress(

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 55 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().
$cart->id_address_delivery,
$cart
);
}
if (0 !== (int) $cart->id_address_invoice && !isset($cartAddresses[$cart->id_address_invoice])) {
$cartAddresses[$cart->id_address_invoice] = $this->buildCartAddress(

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0.0)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().

Check failure on line 61 in src/Cart/Query/GetCartForPaymentQueryHandler.php

View workflow job for this annotation

GitHub Actions / PHPStan (latest)

Call to an undefined method PrestaShop\Module\PrestashopCheckout\Cart\Query\GetCartForPaymentQueryHandler::buildCartAddress().
$cart->id_address_invoice,
$cart
);
}

return array_values($cartAddresses);
}
}
83 changes: 83 additions & 0 deletions src/Cart/Query/GetCartForPaymentQueryResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/

namespace PrestaShop\Module\PrestashopCheckout\Cart\Query;

use Cart;

class GetCartForPaymentQueryResult
{
/**
* @var Cart
*/
private $cart;
/**
* @var array
*/
private $products;
/**
* @var array
*/
private $deliveryAddress;
/**
* @var array
*/
private $invoiceAddress;

public function __construct(Cart $cart, $products, $deliveryAddress, $invoiceAddress)
{
$this->cart = $cart;
$this->products = $products;
$this->deliveryAddress = $deliveryAddress;
$this->invoiceAddress = $invoiceAddress;
}

/**
* @return Cart
*/
public function getCart()
{
return $this->cart;
}

/**
* @return array
*/
public function getProducts()
{
return $this->products;
}

/**
* @return array
*/
public function getDeliveryAddress()
{
return $this->deliveryAddress;
}

/**
* @return array
*/
public function getInvoiceAddress()
{
return $this->invoiceAddress;
}
}
Loading