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

Migrate order action and status block #16022

Merged
merged 3 commits into from
Oct 28, 2019
Merged
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 admin-dev/themes/new-theme/scss/components/_button.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.btn {
&.btn-action {
color: black;
background-color: white;
border-radius: 4px;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
Expand Down
12 changes: 11 additions & 1 deletion src/Adapter/Order/QueryHandler/GetOrderForViewingHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,17 @@ private function getOrderDocuments(Order $order): OrderDocumentsForViewing
);
}

return new OrderDocumentsForViewing($documentsForViewing);
$canGenerateInvoice = Configuration::get('PS_INVOICE') &&
count($order->getInvoicesCollection()) &&
$order->invoice_number;

$canGenerateDeliverySlip = (bool) $order->delivery_number;

return new OrderDocumentsForViewing(
$canGenerateInvoice,
$canGenerateDeliverySlip,
$documentsForViewing
);
}

private function getOrderShipping(Order $order): OrderShippingForViewing
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Domain/Order/QueryResult/OrderCarrierForViewing.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ class OrderCarrierForViewing
/**
* @param int $orderCarrierId
* @param DateTimeImmutable $date
* @param string $name
* @param string $name Carrier name or null in case of virtual order
sarjon marked this conversation as resolved.
Show resolved Hide resolved
* @param string $weight
* @param int $carrierId
* @param string $price
* @param string $price Price or null in case of virtual order
sarjon marked this conversation as resolved.
Show resolved Hide resolved
* @param string|null $trackingUrl
* @param string|null $trackingNumber
* @param bool $canEdit
*/
public function __construct(
int $orderCarrierId,
DateTimeImmutable $date,
string $name,
?string $name,
string $weight,
int $carrierId,
string $price,
?string $price,
?string $trackingUrl,
?string $trackingNumber,
bool $canEdit
Expand Down Expand Up @@ -127,7 +127,7 @@ public function getDate(): DateTimeImmutable
/**
* @return string
*/
public function getName(): string
public function getName(): ?string
{
return $this->name;
}
Expand All @@ -143,7 +143,7 @@ public function getCarrierId(): int
/**
* @return string
*/
public function getPrice(): string
public function getPrice(): ?string
{
return $this->price;
}
Expand Down
33 changes: 32 additions & 1 deletion src/Core/Domain/Order/QueryResult/OrderDocumentsForViewing.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,28 @@ class OrderDocumentsForViewing
private $documents = [];

/**
* @var bool
*/
private $canGenerateInvoice;

/**
* @var bool
*/
private $canGenerateDeliverySlip;

/**
* @param bool $canGenerateInvoice
* @param bool $canGenerateDeliverySlip
* @param OrderDocumentForViewing[] $documents
*/
public function __construct(array $documents)
public function __construct(bool $canGenerateInvoice, bool $canGenerateDeliverySlip, array $documents)
{
foreach ($documents as $document) {
$this->add($document);
}

$this->canGenerateInvoice = $canGenerateInvoice;
$this->canGenerateDeliverySlip = $canGenerateDeliverySlip;
}

/**
Expand All @@ -51,6 +66,22 @@ public function getDocuments(): array
return $this->documents;
}

/**
* @return bool
*/
public function canGenerateInvoice(): bool
{
return $this->canGenerateInvoice;
}

/**
* @return bool
*/
public function canGenerateDeliverySlip(): bool
{
return $this->canGenerateDeliverySlip;
}

private function add(OrderDocumentForViewing $document): void
{
$this->documents[] = $document;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,10 @@ services:
- '@=service("prestashop.user_provider").getUsername()'
tags:
- { name: twig.extension }

prestashop.bundle.twig.extension.localization_extension:
class: 'PrestaShopBundle\Twig\Extension\LocalizationExtension'
arguments:
- '@=service("prestashop.adapter.legacy.context").getContext().language.date_format_full'
tags:
- { name: twig.extension }
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{% endif %}
</td>
<td class="text-right">
{{ status.createdAt.format('Y-m-d H:i:s') }}
{{ status.createdAt|date_format_full }}
</td>
<td class="text-right">
{% if status.withEmail %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,26 @@
{{ form_rest(updateOrderStatusActionBarForm) }}
</div>
{{ form_end(updateOrderStatusActionBarForm) }}

{% if orderForViewing.documents.canGenerateInvoice %}
<form class="form-inline d-inline-block form-horizontal ml-2">
<div class="input-group">
<a href="{{ path('admin_orders_generate_invoice_pdf', {'orderId': orderForViewing.id}) }}" class="btn btn-action">
<i class="material-icons">receipt</i>
{{ 'View invoice'|trans({}, 'Admin.Orderscustomers.Feature') }}
</a>
</div>
</form>
{% endif %}

{% if orderForViewing.documents.canGenerateDeliverySlip %}
<form class="form-inline d-inline-block form-horizontal ml-2">
<div class="input-group">
<a href="{{ path('admin_orders_generate_delivery_slip_pdf', {'orderId': orderForViewing.id}) }}" class="btn btn-action">
<i class="material-icons">local_shipping</i>
{{ 'View delivery slip'|trans({}, 'Admin.Orderscustomers.Feature') }}
</a>
</div>
</form>
{% endif %}
</div>
64 changes: 64 additions & 0 deletions src/PrestaShopBundle/Twig/Extension/LocalizationExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* 2007-2019 PrestaShop SA 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
*/

namespace PrestaShopBundle\Twig\Extension;

use DateTime;
use DateTimeInterface;
use Twig\Extension\AbstractExtension;
use Twig_SimpleFilter;

class LocalizationExtension extends AbstractExtension
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matks wdyt about name?

Also, I think we should document this extension as it is very useful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit generic ... but it works for now. We should monitor what else we'll put in it (right now it's a DateFormatterExtension). If we add more and more localization-related functions in it, there it works 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you are right, it's a little generic, maybe we can rename it to DateFormatterExtension instead? Now when I think about it, it wouldn't make sense to inject multiple services, if we need more, lets say for price display, we could better create PriceFormatterExtension.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to have multiple services if they are part of the same component. See PrestaShopBundle\Twig\Extension\GridExtension 😉

Price formats and date formats are both linked to localization so I think it's alright to have them side by side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(it's unlikely that you'd need to localize dates but not prices)

{
/**
* @var string
*/
private $dateFormatFull;

/**
* @param string $contextDateFormatFull
*/
public function __construct(string $contextDateFormatFull)
{
$this->dateFormatFull = $contextDateFormatFull;
}

public function getFilters(): array
{
return [
new Twig_SimpleFilter('date_format_full', [$this, 'dateFormatFull']),
matks marked this conversation as resolved.
Show resolved Hide resolved
];
}

public function dateFormatFull($date): string
{
if (!$date instanceof DateTimeInterface) {
$date = new DateTime($date);
}

return $date->format($this->dateFormatFull);
}
}