Skip to content

Commit

Permalink
Merge pull request PrestaShop#23078 from Progi1984/issue22983
Browse files Browse the repository at this point in the history
Fixed missing APE/SIRET Code in BackOffice Order View
  • Loading branch information
Progi1984 authored Feb 8, 2021
2 parents 964749e + 0e95b96 commit ca07ffe
Show file tree
Hide file tree
Showing 8 changed files with 232 additions and 11 deletions.
38 changes: 30 additions & 8 deletions src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

use Address;
use Carrier;
use Configuration;
use ConnectionsSource;
use Context;
use Country;
Expand All @@ -43,6 +42,7 @@
use OrderSlip;
use OrderState;
use PrestaShop\Decimal\Number;
use PrestaShop\PrestaShop\Adapter\Configuration;
use PrestaShop\PrestaShop\Adapter\Customer\CustomerDataProvider;
use PrestaShop\PrestaShop\Adapter\Order\AbstractOrderHandler;
use PrestaShop\PrestaShop\Core\Domain\Exception\InvalidSortingException;
Expand Down Expand Up @@ -78,6 +78,7 @@
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderSourcesForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderStatusForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\ValueObject\OrderId;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use PrestaShop\PrestaShop\Core\Image\Parser\ImageTagSourceParserInterface;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;
use PrestaShop\PrestaShop\Core\Localization\Locale;
Expand Down Expand Up @@ -113,6 +114,11 @@ final class GetOrderForViewingHandler extends AbstractOrderHandler implements Ge
*/
private $customerDataProvider;

/**
* @var Configuration
*/
private $configuration;

/**
* @var Context
*/
Expand All @@ -138,7 +144,8 @@ public function __construct(
Locale $locale,
Context $context,
CustomerDataProvider $customerDataProvider,
GetOrderProductsForViewingHandlerInterface $getOrderProductsForViewingHandler
GetOrderProductsForViewingHandlerInterface $getOrderProductsForViewingHandler,
Configuration $configuration
) {
$this->translator = $translator;
$this->contextLanguageId = $contextLanguageId;
Expand All @@ -147,6 +154,7 @@ public function __construct(
$this->context = $context;
$this->customerDataProvider = $customerDataProvider;
$this->getOrderProductsForViewingHandler = $getOrderProductsForViewingHandler;
$this->configuration = $configuration;
}

/**
Expand All @@ -164,7 +172,11 @@ public function handle(GetOrderForViewing $query): OrderForViewing
$this->translator->trans('Tax included', [], 'Admin.Global') :
$this->translator->trans('Tax excluded', [], 'Admin.Global');

$invoiceManagementIsEnabled = (bool) Configuration::get('PS_INVOICE', null, null, $order->id_shop);
$invoiceManagementIsEnabled = (bool) $this->configuration->get(
'PS_INVOICE',
null,
new ShopConstraint((int) $order->id_shop, (int) $order->id_shop_group)
);

return new OrderForViewing(
(int) $order->id,
Expand Down Expand Up @@ -224,6 +236,8 @@ private function getOrderCustomer(Order $order): ?OrderCustomerForViewing
$customerStats = $customer->getStats();
$totalSpentSinceRegistration = Tools::convertPrice($customerStats['total_orders'], $order->id_currency);

$isB2BEnabled = $this->configuration->getBoolean('PS_B2B_ENABLE');

return new OrderCustomerForViewing(
$customer->id,
$customer->firstname,
Expand All @@ -234,7 +248,9 @@ private function getOrderCustomer(Order $order): ?OrderCustomerForViewing
$totalSpentSinceRegistration !== null ? $this->locale->formatPrice($totalSpentSinceRegistration, $currency->iso_code) : '',
$customerStats['nb_orders'],
$customer->note,
(bool) $customer->is_guest
(bool) $customer->is_guest,
$isB2BEnabled ? ($customer->ape ?: '') : '',
$isB2BEnabled ? ($customer->siret ?: '') : ''
);
}

Expand Down Expand Up @@ -394,9 +410,14 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing
}
}
} elseif (OrderDocumentType::DELIVERY_SLIP === $type) {
$conf = $this->configuration->get(
'PS_DELIVERY_PREFIX',
null,
new ShopConstraint($order->id_shop, $order->id_shop_group)
);
$number = sprintf(
'%s%06d',
Configuration::get('PS_DELIVERY_PREFIX', $this->contextLanguageId, null, $order->id_shop),
$conf[$this->contextLanguageId] ?? '',
$document->delivery_number
);
$amount = $this->locale->formatPrice(
Expand All @@ -405,9 +426,10 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing
);
$numericAmount = $document->total_shipping_tax_incl;
} elseif (OrderDocumentType::CREDIT_SLIP) {
$conf = $this->configuration->get('PS_CREDIT_SLIP_PREFIX');
$number = sprintf(
'%s%06d',
Configuration::get('PS_CREDIT_SLIP_PREFIX', $this->contextLanguageId),
$conf[$this->contextLanguageId] ?? '',
$document->id
);
$amount = $this->locale->formatPrice(
Expand All @@ -430,7 +452,7 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing
);
}

$canGenerateInvoice = Configuration::get('PS_INVOICE') &&
$canGenerateInvoice = $this->configuration->get('PS_INVOICE') &&
count($order->getInvoicesCollection()) &&
$order->invoice_number;

Expand Down Expand Up @@ -484,7 +506,7 @@ private function getOrderShipping(Order $order): OrderShippingForViewing
$trackingUrl = str_replace('@', $item['tracking_number'], $item['url']);
}

$weight = sprintf('%.3f %s', $item['weight'], Configuration::get('PS_WEIGHT_UNIT'));
$weight = sprintf('%.3f %s', $item['weight'], $this->configuration->get('PS_WEIGHT_UNIT'));

$carriers[] = new OrderCarrierForViewing(
(int) $item['id_order_carrier'],
Expand Down
36 changes: 34 additions & 2 deletions src/Core/Domain/Order/QueryResult/OrderCustomerForViewing.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class OrderCustomerForViewing
private $validOrdersPlaced;

/**
* @var string
* @var string|null
*/
private $privateNote;

Expand All @@ -80,6 +80,16 @@ class OrderCustomerForViewing
*/
private $isGuest;

/**
* @var string
*/
private $ape;

/**
* @var string
*/
private $siret;

/**
* @param int $id
* @param string $firstName
Expand All @@ -91,6 +101,8 @@ class OrderCustomerForViewing
* @param int $validOrdersPlaced
* @param string|null $privateNote
* @param bool $isGuest
* @param string $ape
* @param string $siret
*/
public function __construct(
int $id,
Expand All @@ -102,7 +114,9 @@ public function __construct(
string $totalSpentSinceRegistration,
int $validOrdersPlaced,
?string $privateNote,
bool $isGuest
bool $isGuest,
string $ape = '',
string $siret = ''
) {
$this->id = $id;
$this->firstName = $firstName;
Expand All @@ -114,6 +128,8 @@ public function __construct(
$this->validOrdersPlaced = $validOrdersPlaced;
$this->privateNote = $privateNote;
$this->isGuest = $isGuest;
$this->ape = $ape;
$this->siret = $siret;
}

/**
Expand Down Expand Up @@ -195,4 +211,20 @@ public function isGuest(): bool
{
return $this->isGuest;
}

/**
* @return string
*/
public function getApe(): string
{
return $this->ape;
}

/**
* @return string
*/
public function getSiret(): string
{
return $this->siret;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ services:
- '@=service("prestashop.adapter.legacy.context").getContext()'
- '@prestashop.adapter.data_provider.customer'
- '@prestashop.adapter.order.query_handler.get_order_products_for_viewing_handler'
- '@prestashop.adapter.legacy.configuration'
tags:
- name: tactician.handler
command: PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderForViewing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@
</p>
<p>{{ orderForViewing.customer.accountRegistrationDate|date_format_full }}</p>
{% endif %}

{% if orderForViewing.customer.siret is not empty %}
<p class="mb-1">
<strong>{{ 'SIRET'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong>
</p>
<p>{{ orderForViewing.customer.siret }}</p>
{% endif %}

{% if orderForViewing.customer.ape is not empty %}
<p class="mb-1 d-block d-md-none">
<strong>{{ 'APE'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong>
</p>
<p class="d-block d-md-none">{{ orderForViewing.customer.ape }}</p>
{% endif %}
</div>
<div id="validatedOrders" class="col-md-6">
<p class="mb-1">
Expand All @@ -95,6 +109,13 @@
<span class="badge rounded badge-dark">{{ orderForViewing.customer.totalSpentSinceRegistration }}</span>
</p>
{% endif %}

{% if orderForViewing.customer.ape is not empty %}
<p class="mb-1 d-none d-md-block">
<strong>{{ 'APE'|trans({}, 'Admin.Orderscustomers.Feature') }}</strong>
</p>
<p class="d-none d-md-block">{{ orderForViewing.customer.ape }}</p>
{% endif %}
</div>
</div>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ public function customerHasAddressInCountry($reference, $isoCode)
throw new RuntimeException(sprintf('Customer does not have address in "%s" country', $isoCode));
}

/**
* @Given /^the customer "(.+)" has SIRET "(.+)"$/
*/
public function customerHasSIRET(string $reference, string $siret): void
{
$customer = $this->getCustomerByReference($reference);
$customer->siret = $siret;
$customer->save();
}

/**
* @Given /^the customer "(.+)" has APE "(.+)"$/
*/
public function customerHasAPE(string $reference, string $ape): void
{
$customer = $this->getCustomerByReference($reference);
$customer->ape = $ape;
$customer->save();
}

/**
* @When /^I am logged in as "(.+)"$/
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?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 Open Software License (OSL 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/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 [email protected] 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://devdocs.prestashop.com/ for more information.
*
* @author PrestaShop SA and Contributors <[email protected]>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace Tests\Integration\Behaviour\Features\Context\Domain;

use PHPUnit\Framework\Assert as Assert;
use PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderCustomerForViewing;
use PrestaShop\PrestaShop\Core\Domain\Order\QueryResult\OrderForViewing;
use Tests\Integration\Behaviour\Features\Context\SharedStorage;

class OrderCustomerFeatureContext extends AbstractDomainFeatureContext
{
/**
* @Then /^the customer of the order "(.+)" has the APE Code "(.*)"$/
*
* @param string $orderReference
* @param string $ape
*/
public function orderCustomerHasAPECode(string $orderReference, string $ape): void
{
$orderId = SharedStorage::getStorage()->get($orderReference);
/** @var OrderForViewing $orderForViewing */
$orderForViewing = $this->getQueryBus()->handle(new GetOrderForViewing($orderId));
/** @var OrderCustomerForViewing $orderCustomerForViewing */
$orderCustomerForViewing = $orderForViewing->getCustomer();
Assert::assertSame(
$ape,
$orderCustomerForViewing->getApe(),
sprintf(
'Expected customer with id "%d" has APE code "%s" but received "%s"',
$orderCustomerForViewing->getId(),
$orderCustomerForViewing->getApe(),
$ape
)
);
}

/**
* @Then /^the customer of the order "(.+)" has the SIRET Code "(.*)"$/
*
* @param string $orderReference
* @param string $siret
*/
public function orderCustomerHasSIRETCode(string $orderReference, string $siret): void
{
$orderId = SharedStorage::getStorage()->get($orderReference);
/** @var OrderForViewing $orderForViewing */
$orderForViewing = $this->getQueryBus()->handle(new GetOrderForViewing($orderId));
/** @var OrderCustomerForViewing $orderCustomerForViewing */
$orderCustomerForViewing = $orderForViewing->getCustomer();

Assert::assertSame(
$siret,
$orderCustomerForViewing->getSiret(),
sprintf(
'Expected customer with id "%d" has SIRET code "%s" but received "%s"',
$orderCustomerForViewing->getId(),
$orderCustomerForViewing->getSiret(),
$siret
)
);
}
}
Loading

0 comments on commit ca07ffe

Please sign in to comment.