Skip to content
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());
}

/**
* @param Cart $cart
*
* @return CartAddress[]
*/
private function getAddresses(Cart $cart)
{
$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);
}

// 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(
$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(
$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;
}
}