Initial commit

This commit is contained in:
2020-10-07 10:37:15 +02:00
commit ce5f440392
28157 changed files with 4429172 additions and 0 deletions

View File

@@ -0,0 +1,198 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use Symfony\Component\Translation\TranslatorInterface;
abstract class AbstractCheckoutStepCore implements CheckoutStepInterface
{
private $smarty;
private $translator;
/**
* @var CheckoutProcess
*/
private $checkoutProcess;
private $title;
protected $step_is_reachable = false;
protected $step_is_complete = false;
protected $step_is_current = false;
protected $context;
protected $template;
protected $unreachableStepTemplate = 'checkout/_partials/steps/unreachable.tpl';
public function __construct(Context $context, TranslatorInterface $translator)
{
$this->context = $context;
$this->smarty = $context->smarty;
$this->translator = $translator;
}
public function setTemplate($templatePath)
{
$this->template = $templatePath;
return $this;
}
public function getTemplate()
{
if ($this->isReachable()) {
return $this->template;
} else {
return $this->unreachableStepTemplate;
}
}
protected function getTranslator()
{
return $this->translator;
}
protected function renderTemplate($template, array $extraParams = array(), array $params = array())
{
$defaultParams = array(
'title' => $this->getTitle(),
'step_is_complete' => (int) $this->isComplete(),
'step_is_reachable' => (int) $this->isReachable(),
'step_is_current' => (int) $this->isCurrent(),
);
$scope = $this->smarty->createData(
$this->smarty
);
$scope->assign(array_merge($defaultParams, $extraParams, $params));
$tpl = $this->smarty->createTemplate(
$template,
$scope
);
return $tpl->fetch();
}
public function setTitle($title)
{
$this->title = $title;
return $this;
}
public function getTitle()
{
return $this->title;
}
public function setCheckoutProcess(CheckoutProcess $checkoutProcess)
{
$this->checkoutProcess = $checkoutProcess;
return $this;
}
public function getCheckoutProcess()
{
return $this->checkoutProcess;
}
public function getCheckoutSession()
{
return $this->getCheckoutProcess()->getCheckoutSession();
}
public function setReachable($step_is_reachable)
{
$this->step_is_reachable = $step_is_reachable;
return $this;
}
public function isReachable()
{
return $this->step_is_reachable;
}
public function setComplete($step_is_complete)
{
$this->step_is_complete = $step_is_complete;
return $this;
}
public function isComplete()
{
return $this->step_is_complete;
}
public function setCurrent($step_is_current)
{
$this->step_is_current = $step_is_current;
return $this;
}
public function isCurrent()
{
return $this->step_is_current;
}
public function getIdentifier()
{
// SomeClassNameLikeThis => some-class-name-like-this
return Tools::camelCaseToKebabCase(get_class($this));
}
public function getDataToPersist()
{
return array();
}
public function restorePersistedData(array $data)
{
return $this;
}
/**
* Find next step and mark it as current
*/
public function setNextStepAsCurrent()
{
$steps = $this->getCheckoutProcess()->getSteps();
$next = false;
foreach ($steps as $step) {
if ($next === true) {
$step->step_is_current = true;
break;
}
if ($step === $this) {
$next = true;
}
}
}
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
/**
* Class AddressValidatorCore.
*
* Validates addresses held by common PrestaShop objects (cart, customer...)
*/
class AddressValidatorCore
{
/**
* Validates cart addresses
* Returns an array of invalid address IDs.
*
* @param Cart $cart
* The cart holding the addresses to be inspected
*
* @return array
* The invalid address ids. Empty if everything is ok.
*/
public function validateCartAddresses(Cart $cart)
{
$invalidAddressIds = array();
$addressesIds = array(
$cart->id_address_delivery,
$cart->id_address_invoice,
);
foreach ($addressesIds as $idAddress) {
$address = new CustomerAddress((int) $idAddress);
try {
$address->validateFields();
} catch (PrestaShopException $e) {
$invalidAddressIds[] = (int) $idAddress;
}
}
return $invalidAddressIds;
}
/**
* Validates given customer's addresses
* Returns an array of invalid address IDs.
*
* @param Customer $customer
* The customer holding the addresses to be inspected
* @param Language $language
* The language in which addresses should be validated
*
* @return array The invalid address ids. Empty if everything is ok.
* The invalid address ids. Empty if everything is ok.
*/
public function validateCustomerAddresses(Customer $customer, Language $language)
{
$invalidAddresses = array();
$addresses = $customer->getAddresses($language->id);
if (is_array($addresses)) {
foreach ($addresses as $address) {
try {
$adressObject = new CustomerAddress((int) $address['id_address']);
$adressObject->validateFields();
} catch (PrestaShopException $e) {
$invalidAddresses[] = (int) $address['id_address'];
}
}
}
return $invalidAddresses;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class CartChecksumCore implements ChecksumInterface
{
public $addressChecksum = null;
private $separator = '_';
private $subseparator = '-';
public function __construct(AddressChecksum $addressChecksum)
{
$this->addressChecksum = $addressChecksum;
}
public function generateChecksum($cart)
{
$uniq_id = '';
$uniq_id .= $cart->id_shop;
$uniq_id .= $this->separator;
$uniq_id .= $cart->id_customer;
$uniq_id .= $this->separator;
$uniq_id .= $cart->id_guest;
$uniq_id .= $this->separator;
$uniq_id .= $cart->id_currency;
$uniq_id .= $this->separator;
$uniq_id .= $cart->id_lang;
$uniq_id .= $this->separator;
$uniq_id .= $this->addressChecksum->generateChecksum(new Address($cart->id_address_delivery));
$uniq_id .= $this->separator;
$uniq_id .= $this->addressChecksum->generateChecksum(new Address($cart->id_address_invoice));
$uniq_id .= $this->separator;
$products = $cart->getProducts($refresh = true);
foreach ($products as $product) {
$uniq_id .= $product['id_shop']
. $this->subseparator
. $product['id_product']
. $this->subseparator
. $product['id_product_attribute']
. $this->subseparator
. $product['cart_quantity']
. $this->subseparator
. $product['total_wt'];
$uniq_id .= $this->separator;
}
$uniq_id = rtrim($uniq_id, $this->separator);
$uniq_id = rtrim($uniq_id, $this->subseparator);
return sha1($uniq_id);
}
}

View File

@@ -0,0 +1,306 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use Symfony\Component\Translation\TranslatorInterface;
class CheckoutAddressesStepCore extends AbstractCheckoutStep
{
protected $template = 'checkout/_partials/steps/addresses.tpl';
private $addressForm;
private $use_same_address = true;
private $show_delivery_address_form = false;
private $show_invoice_address_form = false;
private $form_has_continue_button = false;
public function __construct(
Context $context,
TranslatorInterface $translator,
CustomerAddressForm $addressForm
) {
parent::__construct($context, $translator);
$this->addressForm = $addressForm;
}
public function getDataToPersist()
{
return array(
'use_same_address' => $this->use_same_address,
);
}
public function restorePersistedData(array $data)
{
if (array_key_exists('use_same_address', $data)) {
$this->use_same_address = $data['use_same_address'];
}
return $this;
}
public function handleRequest(array $requestParams = array())
{
$this->addressForm->setAction($this->getCheckoutSession()->getCheckoutURL());
if (array_key_exists('use_same_address', $requestParams)) {
$this->use_same_address = (bool) $requestParams['use_same_address'];
if (!$this->use_same_address) {
$this->setCurrent(true);
}
}
if (isset($requestParams['cancelAddress'])) {
if ($requestParams['cancelAddress'] === 'invoice') {
if ($this->getCheckoutSession()->getCustomerAddressesCount() < 2) {
$this->use_same_address = true;
}
}
$this->setCurrent(true);
}
// Can't really hurt to set the firstname and lastname.
$this->addressForm->fillWith(array(
'firstname' => $this->getCheckoutSession()->getCustomer()->firstname,
'lastname' => $this->getCheckoutSession()->getCustomer()->lastname,
));
if (isset($requestParams['saveAddress'])) {
$saved = $this->addressForm->fillWith($requestParams)->submit();
if (!$saved) {
$this->setCurrent(true);
$this->getCheckoutProcess()->setHasErrors(true);
if ($requestParams['saveAddress'] === 'delivery') {
$this->show_delivery_address_form = true;
} else {
$this->show_invoice_address_form = true;
}
} else {
if ($requestParams['saveAddress'] === 'delivery') {
$this->use_same_address = isset($requestParams['use_same_address']);
}
$id_address = $this->addressForm->getAddress()->id;
if ($requestParams['saveAddress'] === 'delivery') {
$this->getCheckoutSession()->setIdAddressDelivery($id_address);
if ($this->use_same_address) {
$this->getCheckoutSession()->setIdAddressInvoice($id_address);
}
} else {
$this->getCheckoutSession()->setIdAddressInvoice($id_address);
}
}
} elseif (isset($requestParams['newAddress'])) {
// while a form is open, do not go to next step
$this->setCurrent(true);
if ($requestParams['newAddress'] === 'delivery') {
$this->show_delivery_address_form = true;
} else {
$this->show_invoice_address_form = true;
}
$this->addressForm->fillWith($requestParams);
$this->form_has_continue_button = $this->use_same_address;
} elseif (isset($requestParams['editAddress'])) {
// while a form is open, do not go to next step
$this->setCurrent(true);
if ($requestParams['editAddress'] === 'delivery') {
$this->show_delivery_address_form = true;
} else {
$this->show_invoice_address_form = true;
}
$this->addressForm->loadAddressById($requestParams['id_address']);
} elseif (isset($requestParams['deleteAddress'])) {
$addressPersister = new CustomerAddressPersister(
$this->context->customer,
$this->context->cart,
Tools::getToken(true, $this->context)
);
$deletionResult = (bool) $addressPersister->delete(
new Address((int) Tools::getValue('id_address'), $this->context->language->id),
Tools::getValue('token')
);
if ($deletionResult) {
$this->context->controller->success[] = $this->getTranslator()->trans(
'Address successfully deleted!',
array(),
'Shop.Notifications.Success'
);
$this->context->controller->redirectWithNotifications(
$this->getCheckoutSession()->getCheckoutURL()
);
} else {
$this->getCheckoutProcess()->setHasErrors(true);
$this->context->controller->errors[] = $this->getTranslator()->trans(
'Could not delete address.',
array(),
'Shop.Notifications.Error'
);
}
}
if (isset($requestParams['confirm-addresses'])) {
if (isset($requestParams['id_address_delivery'])) {
$id_address = $requestParams['id_address_delivery'];
if (!Customer::customerHasAddress($this->getCheckoutSession()->getCustomer()->id, $id_address)) {
$this->getCheckoutProcess()->setHasErrors(true);
} else {
if ($this->getCheckoutSession()->getIdAddressDelivery() != $id_address) {
$this->setCurrent(true);
$this->getCheckoutProcess()->invalidateAllStepsAfterCurrent();
}
$this->getCheckoutSession()->setIdAddressDelivery($id_address);
if ($this->use_same_address) {
$this->getCheckoutSession()->setIdAddressInvoice($id_address);
}
}
}
if (isset($requestParams['id_address_invoice'])) {
$id_address = $requestParams['id_address_invoice'];
if (!Customer::customerHasAddress($this->getCheckoutSession()->getCustomer()->id, $id_address)) {
$this->getCheckoutProcess()->setHasErrors(true);
} else {
$this->getCheckoutSession()->setIdAddressInvoice($id_address);
}
}
if (!$this->getCheckoutProcess()->hasErrors()) {
$this->setNextStepAsCurrent();
$this->setComplete(
$this->getCheckoutSession()->getIdAddressInvoice() &&
$this->getCheckoutSession()->getIdAddressDelivery()
);
}
}
$addresses_count = $this->getCheckoutSession()->getCustomerAddressesCount();
if ($addresses_count === 0) {
$this->show_delivery_address_form = true;
} elseif ($addresses_count < 2 && !$this->use_same_address) {
$this->show_invoice_address_form = true;
$this->setComplete(false);
}
if ($this->show_invoice_address_form) {
// show continue button because form is at the end of the step
$this->form_has_continue_button = true;
} elseif ($this->show_delivery_address_form) {
// only show continue button if we're sure
// our form is at the bottom of the step
if ($this->use_same_address || $addresses_count < 2) {
$this->form_has_continue_button = true;
}
}
$this->setTitle($this->getTranslator()->trans('Addresses', array(), 'Shop.Theme.Checkout'));
return $this;
}
public function getTemplateParameters()
{
$idAddressDelivery = (int) $this->getCheckoutSession()->getIdAddressDelivery();
$idAddressInvoice = (int) $this->getCheckoutSession()->getIdAddressInvoice();
$params = array(
'address_form' => $this->addressForm->getProxy(),
'use_same_address' => $this->use_same_address,
'use_different_address_url' => $this->context->link->getPageLink(
'order',
true,
null,
array('use_same_address' => 0)
),
'new_address_delivery_url' => $this->context->link->getPageLink(
'order',
true,
null,
array('newAddress' => 'delivery')
),
'new_address_invoice_url' => $this->context->link->getPageLink(
'order',
true,
null,
array('newAddress' => 'invoice')
),
'id_address' => (int) Tools::getValue('id_address'),
'id_address_delivery' => $idAddressDelivery,
'id_address_invoice' => $idAddressInvoice,
'show_delivery_address_form' => $this->show_delivery_address_form,
'show_invoice_address_form' => $this->show_invoice_address_form,
'form_has_continue_button' => $this->form_has_continue_button,
);
/** @var OrderControllerCore $controller */
$controller = $this->context->controller;
if (isset($controller)) {
$warnings = $controller->checkoutWarning;
$addressWarning = isset($warnings['address'])
? $warnings['address']
: false;
$invalidAddresses = isset($warnings['invalid_addresses'])
? $warnings['invalid_addresses']
: array();
$errors = array();
if (in_array($idAddressDelivery, $invalidAddresses)) {
$errors['delivery_address_error'] = $addressWarning;
}
if (in_array($idAddressInvoice, $invalidAddresses)) {
$errors['invoice_address_error'] = $addressWarning;
}
if ($this->show_invoice_address_form
|| $idAddressInvoice != $idAddressDelivery
|| !empty($errors['invoice_address_error'])
) {
$this->use_same_address = false;
}
// Add specific parameters
$params = array_replace(
$params,
array(
'not_valid_addresses' => implode(',', $invalidAddresses),
'use_same_address' => $this->use_same_address,
),
$errors
);
}
return $params;
}
public function render(array $extraParams = array())
{
return $this->renderTemplate(
$this->getTemplate(),
$extraParams,
$this->getTemplateParameters()
);
}
}

View File

@@ -0,0 +1,215 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
class CheckoutDeliveryStepCore extends AbstractCheckoutStep
{
protected $template = 'checkout/_partials/steps/shipping.tpl';
private $recyclablePackAllowed = false;
private $giftAllowed = false;
private $giftCost = 0;
private $includeTaxes = false;
private $displayTaxesLabel = false;
public function setRecyclablePackAllowed($recyclablePackAllowed)
{
$this->recyclablePackAllowed = $recyclablePackAllowed;
return $this;
}
public function isRecyclablePackAllowed()
{
return $this->recyclablePackAllowed;
}
public function setGiftAllowed($giftAllowed)
{
$this->giftAllowed = $giftAllowed;
return $this;
}
public function isGiftAllowed()
{
return $this->giftAllowed;
}
public function setGiftCost($giftCost)
{
$this->giftCost = $giftCost;
return $this;
}
public function getGiftCost()
{
return $this->giftCost;
}
public function setIncludeTaxes($includeTaxes)
{
$this->includeTaxes = $includeTaxes;
return $this;
}
public function getIncludeTaxes()
{
return $this->includeTaxes;
}
public function setDisplayTaxesLabel($displayTaxesLabel)
{
$this->displayTaxesLabel = $displayTaxesLabel;
return $this;
}
public function getDisplayTaxesLabel()
{
return $this->displayTaxesLabel;
}
public function getGiftCostForLabel()
{
if ($this->getGiftCost() != 0) {
$taxLabel = '';
$priceFormatter = new PriceFormatter();
if ($this->getIncludeTaxes() && $this->getDisplayTaxesLabel()) {
$taxLabel .= ' tax incl.';
} elseif ($this->getDisplayTaxesLabel()) {
$taxLabel .= ' tax excl.';
}
return $this->getTranslator()->trans(
' (additional cost of %giftcost% %taxlabel%)',
array(
'%giftcost%' => $priceFormatter->convertAndFormat($this->getGiftCost()),
'%taxlabel%' => $taxLabel,
),
'Shop.Theme.Checkout'
);
}
return '';
}
public function handleRequest(array $requestParams = array())
{
if (isset($requestParams['delivery_option'])) {
$this->setComplete(false);
$this->getCheckoutSession()->setDeliveryOption(
$requestParams['delivery_option']
);
$this->getCheckoutSession()->setRecyclable(
isset($requestParams['recyclable']) ? $requestParams['recyclable'] : false
);
$useGift = isset($requestParams['gift']) ? $requestParams['gift'] : false;
$this->getCheckoutSession()->setGift(
$useGift,
($useGift && isset($requestParams['gift_message'])) ? $requestParams['gift_message'] : ''
);
}
if (isset($requestParams['delivery_message'])) {
$this->getCheckoutSession()->setMessage($requestParams['delivery_message']);
}
if ($this->isReachable() && isset($requestParams['confirmDeliveryOption'])) {
// we're done if
// - the step was reached (= all previous steps complete)
// - user has clicked on "continue"
// - there are delivery options
// - the is a selected delivery option
// - the module associated to the delivery option confirms
$deliveryOptions = $this->getCheckoutSession()->getDeliveryOptions();
$this->setNextStepAsCurrent();
$this->setComplete(
!empty($deliveryOptions)
&& $this->getCheckoutSession()->getSelectedDeliveryOption()
&& $this->isModuleComplete($requestParams)
);
}
$this->setTitle($this->getTranslator()->trans('Shipping Method', array(), 'Shop.Theme.Checkout'));
Hook::exec('actionCarrierProcess', array('cart' => $this->getCheckoutSession()->getCart()));
}
public function render(array $extraParams = array())
{
return $this->renderTemplate(
$this->getTemplate(),
$extraParams,
array(
'hookDisplayBeforeCarrier' => Hook::exec('displayBeforeCarrier', array('cart' => $this->getCheckoutSession()->getCart())),
'hookDisplayAfterCarrier' => Hook::exec('displayAfterCarrier', array('cart' => $this->getCheckoutSession()->getCart())),
'id_address' => $this->getCheckoutSession()->getIdAddressDelivery(),
'delivery_options' => $this->getCheckoutSession()->getDeliveryOptions(),
'delivery_option' => $this->getCheckoutSession()->getSelectedDeliveryOption(),
'recyclable' => $this->getCheckoutSession()->isRecyclable(),
'recyclablePackAllowed' => $this->isRecyclablePackAllowed(),
'delivery_message' => $this->getCheckoutSession()->getMessage(),
'gift' => array(
'allowed' => $this->isGiftAllowed(),
'isGift' => $this->getCheckoutSession()->getGift()['isGift'],
'label' => $this->getTranslator()->trans(
'I would like my order to be gift wrapped %cost%',
array('%cost%' => $this->getGiftCostForLabel()),
'Shop.Theme.Checkout'
),
'message' => $this->getCheckoutSession()->getGift()['message'],
),
)
);
}
protected function isModuleComplete($requestParams)
{
$deliveryOptions = $this->getCheckoutSession()->getDeliveryOptions();
$currentDeliveryOption = $deliveryOptions[$this->getCheckoutSession()->getSelectedDeliveryOption()];
if (!$currentDeliveryOption['is_module']) {
return true;
}
$isComplete = true;
Hook::exec(
'actionValidateStepComplete',
array(
'step_name' => 'delivery',
'request_params' => $requestParams,
'completed' => &$isComplete,
),
Module::getModuleIdByName($currentDeliveryOption['external_module_name'])
);
return $isComplete;
}
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use Symfony\Component\Translation\TranslatorInterface;
class CheckoutPaymentStepCore extends AbstractCheckoutStep
{
protected $template = 'checkout/_partials/steps/payment.tpl';
private $selected_payment_option;
public function __construct(
Context $context,
TranslatorInterface $translator,
PaymentOptionsFinder $paymentOptionsFinder,
ConditionsToApproveFinder $conditionsToApproveFinder
) {
parent::__construct($context, $translator);
$this->paymentOptionsFinder = $paymentOptionsFinder;
$this->conditionsToApproveFinder = $conditionsToApproveFinder;
}
public function handleRequest(array $requestParams = array())
{
$allProductsInStock = $this->getCheckoutSession()->getCart()->isAllProductsInStock();
if ($allProductsInStock !== true) {
$cartShowUrl = $this->context->link->getPageLink(
'cart',
null,
$this->context->language->id,
array(
'action' => 'show',
),
false,
null,
false
);
Tools::redirect($cartShowUrl);
}
if (isset($requestParams['select_payment_option'])) {
$this->selected_payment_option = $requestParams['select_payment_option'];
}
$this->setTitle(
$this->getTranslator()->trans(
'Payment',
array(),
'Shop.Theme.Checkout'
)
);
}
/**
* @param array $extraParams
*
* @return string
*/
public function render(array $extraParams = array())
{
$isFree = 0 == (float) $this->getCheckoutSession()->getCart()->getOrderTotal(true, Cart::BOTH);
$paymentOptions = $this->paymentOptionsFinder->present($isFree);
$conditionsToApprove = $this->conditionsToApproveFinder->getConditionsToApproveForTemplate();
$deliveryOptions = $this->getCheckoutSession()->getDeliveryOptions();
$deliveryOptionKey = $this->getCheckoutSession()->getSelectedDeliveryOption();
if (isset($deliveryOptions[$deliveryOptionKey])) {
$selectedDeliveryOption = $deliveryOptions[$deliveryOptionKey];
} else {
$selectedDeliveryOption = 0;
}
unset($selectedDeliveryOption['product_list']);
$assignedVars = array(
'is_free' => $isFree,
'payment_options' => $paymentOptions,
'conditions_to_approve' => $conditionsToApprove,
'selected_payment_option' => $this->selected_payment_option,
'selected_delivery_option' => $selectedDeliveryOption,
'show_final_summary' => Configuration::get('PS_FINAL_SUMMARY_ENABLED'),
);
return $this->renderTemplate($this->getTemplate(), $extraParams, $assignedVars);
}
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use Symfony\Component\Translation\TranslatorInterface;
class CheckoutPersonalInformationStepCore extends AbstractCheckoutStep
{
protected $template = 'checkout/_partials/steps/personal-information.tpl';
private $loginForm;
private $registerForm;
private $show_login_form = false;
public function __construct(
Context $context,
TranslatorInterface $translator,
CustomerLoginForm $loginForm,
CustomerForm $registerForm
) {
parent::__construct($context, $translator);
$this->loginForm = $loginForm;
$this->registerForm = $registerForm;
}
public function handleRequest(array $requestParameters = array())
{
// personal info step is always reachable
$this->setReachable(true);
$this->registerForm
->fillFromCustomer(
$this
->getCheckoutProcess()
->getCheckoutSession()
->getCustomer()
);
if (isset($requestParameters['submitCreate'])) {
$this->registerForm->fillWith($requestParameters);
if ($this->registerForm->submit()) {
$this->setNextStepAsCurrent();
$this->setComplete(true);
} else {
$this->setComplete(false);
$this->setCurrent(true);
$this->getCheckoutProcess()->setHasErrors(true)->setNextStepReachable();
}
} elseif (isset($requestParameters['submitLogin'])) {
$this->loginForm->fillWith($requestParameters);
if ($this->loginForm->submit()) {
$this->setNextStepAsCurrent();
$this->setComplete(true);
} else {
$this->getCheckoutProcess()->setHasErrors(true);
$this->show_login_form = true;
}
} elseif (array_key_exists('login', $requestParameters)) {
$this->show_login_form = true;
$this->setCurrent(true);
}
$this->logged_in = $this
->getCheckoutProcess()
->getCheckoutSession()
->customerHasLoggedIn();
if ($this->logged_in && !$this->getCheckoutSession()->getCustomer()->is_guest) {
$this->setComplete(true);
}
$this->setTitle(
$this->getTranslator()->trans(
'Personal Information',
array(),
'Shop.Theme.Checkout'
)
);
}
public function render(array $extraParams = array())
{
return $this->renderTemplate(
$this->getTemplate(),
$extraParams,
array(
'show_login_form' => $this->show_login_form,
'login_form' => $this->loginForm->getProxy(),
'register_form' => $this->registerForm->getProxy(),
'guest_allowed' => $this->getCheckoutSession()->isGuestAllowed(),
'empty_cart_on_logout' => !Configuration::get('PS_CART_FOLLOWING'),
)
);
}
}

View File

@@ -0,0 +1,218 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Foundation\Templating\RenderableInterface;
use PrestaShop\PrestaShop\Core\Foundation\Templating\RenderableProxy;
class CheckoutProcessCore implements RenderableInterface
{
private $smarty;
/**
* @var CheckoutSession
*/
private $checkoutSession;
private $steps = array();
private $has_errors;
private $template = 'checkout/checkout-process.tpl';
public function __construct(
Context $context,
CheckoutSession $checkoutSession
) {
$this->context = $context;
$this->smarty = $this->context->smarty;
$this->checkoutSession = $checkoutSession;
}
public function getTemplate()
{
return $this->template;
}
public function handleRequest(array $requestParameters = array())
{
foreach ($this->getSteps() as $step) {
$step->handleRequest($requestParameters);
}
return $this;
}
public function getCheckoutSession()
{
return $this->checkoutSession;
}
public function addStep(CheckoutStepInterface $step)
{
$step->setCheckoutProcess($this);
$this->steps[] = $step;
return $this;
}
public function getSteps()
{
return $this->steps;
}
public function setTemplate($templatePath)
{
$this->template = $templatePath;
return $this;
}
public function render(array $extraParams = array())
{
$scope = $this->smarty->createData(
$this->smarty
);
$params = array(
'steps' => array_map(function (CheckoutStepInterface $step) {
return array(
'identifier' => $step->getIdentifier(),
'ui' => new RenderableProxy($step),
);
}, $this->getSteps()),
);
$scope->assign(array_merge($extraParams, $params));
$tpl = $this->smarty->createTemplate(
$this->template,
$scope
);
return $tpl->fetch();
}
public function setHasErrors($has_errors = true)
{
$this->has_errors = $has_errors;
return $this;
}
public function hasErrors()
{
return $this->has_errors;
}
public function getDataToPersist()
{
$data = [];
foreach ($this->getSteps() as $step) {
$defaultStepData = array(
'step_is_reachable' => $step->isReachable(),
'step_is_complete' => $step->isComplete(),
);
$stepData = array_merge($defaultStepData, $step->getDataToPersist());
$data[$step->getIdentifier()] = $stepData;
}
return $data;
}
public function restorePersistedData(array $data)
{
foreach ($this->getSteps() as $step) {
$id = $step->getIdentifier();
if (array_key_exists($id, $data)) {
$stepData = $data[$id];
$step
->setReachable($stepData['step_is_reachable'])
->setComplete($stepData['step_is_complete'])
->restorePersistedData($stepData);
}
}
return $this;
}
public function setNextStepReachable()
{
foreach ($this->getSteps() as $step) {
if (!$step->isReachable()) {
$step->setReachable(true);
break;
}
if (!$step->isComplete()) {
break;
}
}
return $this;
}
public function markCurrentStep()
{
$steps = $this->getSteps();
foreach ($steps as $step) {
if ($step->isCurrent()) {
// If a step marked itself as current
// then we assume it has a good reason
// to do so and we don't auto-advance.
return $this;
}
}
foreach ($steps as $position => $step) {
$nextStep = ($position < count($steps) - 1) ? $steps[$position + 1] : null;
if ($step->isReachable() && (!$step->isComplete() || ($nextStep && !$nextStep->isReachable()))) {
$step->setCurrent(true);
return $this;
}
}
return $this;
}
public function invalidateAllStepsAfterCurrent()
{
$markAsUnreachable = false;
foreach ($this->getSteps() as $step) {
if ($markAsUnreachable) {
$step->setComplete(false)->setReachable(false);
}
if ($step->isCurrent()) {
$markAsUnreachable = true;
}
}
return $this;
}
}

View File

@@ -0,0 +1,181 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class CheckoutSessionCore
{
protected $context;
protected $deliveryOptionsFinder;
public function __construct(Context $context, DeliveryOptionsFinder $deliveryOptionsFinder)
{
$this->context = $context;
$this->deliveryOptionsFinder = $deliveryOptionsFinder;
}
public function customerHasLoggedIn()
{
return $this->context->customer->isLogged();
}
public function getCustomer()
{
return $this->context->customer;
}
public function getCart()
{
return $this->context->cart;
}
public function getCustomerAddressesCount()
{
return count($this->getCustomer()->getSimpleAddresses(
$this->context->language->id,
true // no cache
));
}
public function setIdAddressDelivery($id_address)
{
$this->context->cart->updateAddressId($this->context->cart->id_address_delivery, $id_address);
$this->context->cart->id_address_delivery = $id_address;
$this->context->cart->save();
return $this;
}
public function setIdAddressInvoice($id_address)
{
$this->context->cart->id_address_invoice = $id_address;
$this->context->cart->save();
return $this;
}
public function getIdAddressDelivery()
{
return $this->context->cart->id_address_delivery;
}
public function getIdAddressInvoice()
{
return $this->context->cart->id_address_invoice;
}
public function setMessage($message)
{
$this->_updateMessage(Tools::safeOutput($message));
return $this;
}
public function getMessage()
{
if ($message = Message::getMessageByCartId($this->context->cart->id)) {
return $message['message'];
}
return false;
}
private function _updateMessage($messageContent)
{
if ($messageContent) {
if ($oldMessage = Message::getMessageByCartId((int) $this->context->cart->id)) {
$message = new Message((int) $oldMessage['id_message']);
$message->message = $messageContent;
$message->update();
} else {
$message = new Message();
$message->message = $messageContent;
$message->id_cart = (int) $this->context->cart->id;
$message->id_customer = (int) $this->context->cart->id_customer;
$message->add();
}
} else {
if ($oldMessage = Message::getMessageByCartId($this->context->cart->id)) {
$message = new Message($oldMessage['id_message']);
$message->delete();
}
}
return true;
}
public function setDeliveryOption($option)
{
$this->context->cart->setDeliveryOption($option);
return $this->context->cart->update();
}
public function getSelectedDeliveryOption()
{
return $this->deliveryOptionsFinder->getSelectedDeliveryOption();
}
public function getDeliveryOptions()
{
return $this->deliveryOptionsFinder->getDeliveryOptions();
}
public function setRecyclable($option)
{
$this->context->cart->recyclable = (int) $option;
return $this->context->cart->update();
}
public function isRecyclable()
{
return $this->context->cart->recyclable;
}
public function setGift($gift, $gift_message)
{
$this->context->cart->gift = (int) $gift;
$this->context->cart->gift_message = $gift_message;
return $this->context->cart->update();
}
public function getGift()
{
return array(
'isGift' => $this->context->cart->gift,
'message' => $this->context->cart->gift_message,
);
}
public function isGuestAllowed()
{
return Configuration::get('PS_GUEST_CHECKOUT_ENABLED');
}
public function getCheckoutURL()
{
return $this->context->link->getPageLink('order');
}
}

View File

@@ -0,0 +1,49 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Foundation\Templating\RenderableInterface;
interface CheckoutStepInterface extends RenderableInterface
{
public function getTitle();
public function handleRequest(array $requestParameters = array());
public function setCheckoutProcess(CheckoutProcess $checkoutProcess);
public function isReachable();
public function isComplete();
public function isCurrent();
public function getIdentifier();
public function getDataToPersist();
public function restorePersistedData(array $data);
public function getTemplate();
}

View File

@@ -0,0 +1,106 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Checkout\TermsAndConditions;
use Symfony\Component\Translation\TranslatorInterface;
class ConditionsToApproveFinderCore
{
private $translator;
private $context;
public function __construct(
Context $context,
TranslatorInterface $translator
) {
$this->context = $context;
$this->translator = $translator;
}
/**
* @return TermsAndConditions
*/
private function getDefaultTermsAndConditions()
{
$cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id);
$link = $this->context->link->getCMSLink($cms, $cms->link_rewrite, (bool) Configuration::get('PS_SSL_ENABLED'));
$termsAndConditions = new TermsAndConditions();
$termsAndConditions
->setText(
$this->translator->trans('I agree to the [terms of service] and will adhere to them unconditionally.', array(), 'Shop.Theme.Checkout'),
$link
)
->setIdentifier('terms-and-conditions');
return $termsAndConditions;
}
private function getConditionsToApprove()
{
$allConditions = array();
$hookedConditions = Hook::exec('termsAndConditions', array(), null, true);
if (!is_array($hookedConditions)) {
$hookedConditions = array();
}
foreach ($hookedConditions as $hookedCondition) {
if ($hookedCondition instanceof TermsAndConditions) {
$allConditions[] = $hookedCondition;
} elseif (is_array($hookedCondition)) {
foreach ($hookedCondition as $hookedConditionObject) {
if ($hookedConditionObject instanceof TermsAndConditions) {
$allConditions[] = $hookedConditionObject;
}
}
}
}
if (Configuration::get('PS_CONDITIONS')) {
array_unshift($allConditions, $this->getDefaultTermsAndConditions());
}
/*
* If two TermsAndConditions objects have the same identifier,
* the one at the end of the list overrides the first one.
* This allows a module to override the default checkbox
* in a consistent manner.
*/
$reducedConditions = array();
foreach ($allConditions as $condition) {
if ($condition instanceof TermsAndConditions) {
$reducedConditions[$condition->getIdentifier()] = $condition;
}
}
return $reducedConditions;
}
public function getConditionsToApproveForTemplate()
{
return array_map(function (TermsAndConditions $condition) {
return $condition->format();
}, $this->getConditionsToApprove());
}
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Adapter\Presenter\Object\ObjectPresenter;
use PrestaShop\PrestaShop\Adapter\Product\PriceFormatter;
use Symfony\Component\Translation\TranslatorInterface;
class DeliveryOptionsFinderCore
{
private $context;
private $objectPresenter;
private $translator;
private $priceFormatter;
public function __construct(
Context $context,
TranslatorInterface $translator,
ObjectPresenter $objectPresenter,
PriceFormatter $priceFormatter
) {
$this->context = $context;
$this->objectPresenter = $objectPresenter;
$this->translator = $translator;
$this->priceFormatter = $priceFormatter;
}
private function isFreeShipping($cart, array $carrier)
{
$free_shipping = false;
if ($carrier['is_free']) {
$free_shipping = true;
} else {
foreach ($cart->getCartRules() as $rule) {
if ($rule['free_shipping'] && !$rule['carrier_restriction']) {
$free_shipping = true;
break;
}
}
}
return $free_shipping;
}
public function getSelectedDeliveryOption()
{
return current($this->context->cart->getDeliveryOption(null, false, false));
}
public function getDeliveryOptions()
{
$delivery_option_list = $this->context->cart->getDeliveryOptionList();
$include_taxes = !Product::getTaxCalculationMethod((int) $this->context->cart->id_customer) && (int) Configuration::get('PS_TAX');
$display_taxes_label = (Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'));
$carriers_available = array();
if (isset($delivery_option_list[$this->context->cart->id_address_delivery])) {
foreach ($delivery_option_list[$this->context->cart->id_address_delivery] as $id_carriers_list => $carriers_list) {
foreach ($carriers_list as $carriers) {
if (is_array($carriers)) {
foreach ($carriers as $carrier) {
$carrier = array_merge($carrier, $this->objectPresenter->present($carrier['instance']));
$delay = $carrier['delay'][$this->context->language->id];
unset($carrier['instance'], $carrier['delay']);
$carrier['delay'] = $delay;
if ($this->isFreeShipping($this->context->cart, $carriers_list)) {
$carrier['price'] = $this->translator->trans(
'Free',
array(),
'Shop.Theme.Checkout'
);
} else {
if ($include_taxes) {
$carrier['price'] = $this->priceFormatter->format($carriers_list['total_price_with_tax']);
if ($display_taxes_label) {
$carrier['price'] = $this->translator->trans(
'%price% tax incl.',
array('%price%' => $carrier['price']),
'Shop.Theme.Checkout'
);
}
} else {
$carrier['price'] = $this->priceFormatter->format($carriers_list['total_price_without_tax']);
if ($display_taxes_label) {
$carrier['price'] = $this->translator->trans(
'%price% tax excl.',
array('%price%' => $carrier['price']),
'Shop.Theme.Checkout'
);
}
}
}
if (count($carriers) > 1) {
$carrier['label'] = $carrier['price'];
} else {
$carrier['label'] = $carrier['name'] . ' - ' . $carrier['delay'] . ' - ' . $carrier['price'];
}
// If carrier related to a module, check for additionnal data to display
$carrier['extraContent'] = '';
if ($carrier['is_module']) {
if ($moduleId = Module::getModuleIdByName($carrier['external_module_name'])) {
$carrier['extraContent'] = Hook::exec('displayCarrierExtraContent', array('carrier' => $carrier), $moduleId);
}
}
$carriers_available[$id_carriers_list] = $carrier;
}
}
}
}
}
return $carriers_available;
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* 2007-2019 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/OSL-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 license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to https://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2019 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
use PrestaShop\PrestaShop\Core\Payment\PaymentOption;
use PrestaShop\PrestaShop\Core\Payment\PaymentOptionFormDecorator;
use PrestaShopBundle\Service\Hook\HookFinder;
class PaymentOptionsFinderCore extends HookFinder
{
/**
* Collects available payment options from three different hooks.
*
* @return array An array of available payment options
*
* @see HookFinder::find()
*/
public function find() //getPaymentOptions()
{
// Payment options coming from intermediate, deprecated version of the Advanced API
$this->hookName = 'displayPaymentEU';
$rawDisplayPaymentEUOptions = parent::find();
$paymentOptions = array_map(
array('PrestaShop\PrestaShop\Core\Payment\PaymentOption', 'convertLegacyOption'),
$rawDisplayPaymentEUOptions
);
// Advanced payment options coming from regular Advanced API
$this->hookName = 'advancedPaymentOptions';
$paymentOptions = array_merge($paymentOptions, parent::find());
// Payment options coming from regular Advanced API
$this->hookName = 'paymentOptions';
$this->expectedInstanceClasses = array('PrestaShop\PrestaShop\Core\Payment\PaymentOption');
$paymentOptions = array_merge($paymentOptions, parent::find());
// Safety check
foreach ($paymentOptions as $moduleName => $paymentOption) {
if (!is_array($paymentOption)) {
unset($paymentOptions[$moduleName]);
}
}
return $paymentOptions;
}
public function findFree()
{
$freeOption = new PaymentOption();
$freeOption->setModuleName('free_order')
->setCallToActionText(Context::getContext()->getTranslator()->trans('Free order', array(), 'Admin.Orderscustomers.Feature'))
->setAction(Context::getContext()->link->getPageLink('order-confirmation', null, null, 'free_order=1'));
return array('free_order' => array($freeOption));
}
public function present($free = false) //getPaymentOptionsForTemplate()
{
$id = 0;
$find = $free ? $this->findFree() : $this->find();
return array_map(function (array $options) use (&$id) {
return array_map(function (PaymentOption $option) use (&$id) {
++$id;
$formattedOption = $option->toArray();
$formattedOption['id'] = 'payment-option-' . $id;
if ($formattedOption['form']) {
$decorator = new PaymentOptionFormDecorator();
$formattedOption['form'] = $decorator->addHiddenSubmitButton(
$formattedOption['form'],
$formattedOption['id']
);
}
return $formattedOption;
}, $options);
}, $find);
}
}