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

fix(export): allow signature or only_recipient for be #840

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
17 changes: 6 additions & 11 deletions Block/Sales/NewShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use MyParcelNL\Magento\Model\Source\DefaultOptions;
use MyParcelNL\Magento\Helper\Data;
use MyParcelNL\Magento\Model\Sales\TrackTraceHolder;
use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;

class NewShipment extends AbstractItems
{
Expand Down Expand Up @@ -106,17 +107,6 @@ public function hasDefaultOption(string $option, string $carrier): bool
return $this->defaultOptions->hasDefault($option, $carrier);
}

/**
* @param string $option 'large_format'
* @param string $carrier
*
* @return bool
*/
public function hasDefaultLargeFormat(string $option, string $carrier): bool
{
return $this->defaultOptions->hasDefaultLargeFormat($carrier, $option);
}

/**
* Get default value of age check
*
Expand Down Expand Up @@ -181,6 +171,11 @@ public function getCountry()
return $this->order->getShippingAddress()->getCountryId();
}

public function consignmentHasShipmentOption(AbstractConsignment $consignment, string $shipmentOption): bool
{
return $this->dataHelper->consignmentHasShipmentOption($consignment, $shipmentOption);
}

/**
* @return \MyParcelNL\Magento\Block\Sales\NewShipmentForm
*/
Expand Down
1 change: 1 addition & 0 deletions Block/Sales/NewShipmentForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __construct()
AbstractConsignment::SHIPMENT_OPTION_SIGNATURE => __('Signature on receipt'),
AbstractConsignment::SHIPMENT_OPTION_ONLY_RECIPIENT => __('Home address only'),
AbstractConsignment::SHIPMENT_OPTION_AGE_CHECK => __('Age check 18+'),
AbstractConsignment::SHIPMENT_OPTION_HIDE_SENDER => __('Hide sender'),
AbstractConsignment::SHIPMENT_OPTION_LARGE_FORMAT => __('Large package'),
AbstractConsignment::SHIPMENT_OPTION_RETURN => __('Return if no answer'),
AbstractConsignment::SHIPMENT_OPTION_SAME_DAY_DELIVERY => __('Same day delivery'),
Expand Down
26 changes: 22 additions & 4 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,37 @@ public function checkDeliveryType(?int $deliveryType): int
}

/**
* @param int $order_id
* @param int $orderId
* @param string $status
*/
public function setOrderStatus(int $order_id, string $status): void
public function setOrderStatus(int $orderId, string $status): void
{
$order = ObjectManager::getInstance()
->create('\Magento\Sales\Model\Order')
->load($order_id);
->load($orderId);
$order->setState($status)
->setStatus($status);
$order->save();
}

public function consignmentHasShipmentOption(AbstractConsignment $consignment, string $shipmentOption): bool
{
/**
* Business logic determining what shipment options to show, if any.
*/
if (AbstractConsignment::CC_NL === $consignment->getCountry()) {
return $consignment->canHaveShipmentOption($shipmentOption);
}

// For PostNL in Belgium - only recipient-only/signature is available
if (AbstractConsignment::CC_BE === $consignment->getCountry() && CarrierPostNL::NAME === $consignment->getCarrierName()) {
return in_array($shipmentOption, [
AbstractConsignment::SHIPMENT_OPTION_ONLY_RECIPIENT,
AbstractConsignment::SHIPMENT_OPTION_SIGNATURE], true);
}

return;
// No shipment options available in any other cases
return false;
}

/**
Expand Down
21 changes: 13 additions & 8 deletions Helper/ShipmentOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class ShipmentOptions
*/
private $order;

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

/**
* @param \MyParcelNL\Magento\Model\Source\DefaultOptions $defaultOptions
* @param \MyParcelNL\Magento\Helper\Data $helper
Expand All @@ -77,6 +82,7 @@ public function __construct(
$this->objectManager = $objectManager;
$this->carrier = $carrier;
$this->options = $options;
$this->cc = $order->getShippingAddress() ? $order->getShippingAddress()->getCountryId() : null;
}

/**
Expand All @@ -92,6 +98,10 @@ public function getInsurance(): int
*/
public function hasSignature(): bool
{
if (AbstractConsignment::CC_BE === $this->cc && $this->hasOnlyRecipient()) {
return false;
}

$signatureFromOptions = self::getValueOfOptionWhenSet(self::SIGNATURE, $this->options);

return $signatureFromOptions ?? $this->optionIsEnabled(self::SIGNATURE);
Expand Down Expand Up @@ -132,10 +142,7 @@ public function hasReturn(): bool
*/
public function hasAgeCheck(): bool
{
$countryId = $this->order->getShippingAddress()
->getCountryId();

if (AbstractConsignment::CC_NL !== $countryId) {
if (AbstractConsignment::CC_NL !== $this->cc) {
return false;
}

Expand Down Expand Up @@ -265,14 +272,12 @@ public static function getValueOfOptionWhenSet(string $key, array $options): ?bo
*/
public function hasLargeFormat(): bool
{
$countryId = $this->order->getShippingAddress()->getCountryId();

if (! in_array($countryId, AbstractConsignment::EURO_COUNTRIES)) {
if (! in_array($this->cc, AbstractConsignment::EURO_COUNTRIES)) {
return false;
}

$largeFormatFromOptions = self::getValueOfOptionWhenSet(self::LARGE_FORMAT, $this->options);
$largeFormatFromSettings = self::$defaultOptions->hasDefaultLargeFormat($this->carrier, self::LARGE_FORMAT);
$largeFormatFromSettings = self::$defaultOptions->hasDefault(self::LARGE_FORMAT, $this->carrier);

return $largeFormatFromOptions ?? $largeFormatFromSettings;
}
Expand Down
6 changes: 3 additions & 3 deletions Model/Sales/TrackTraceHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options)

$this->consignment = (ConsignmentFactory::createByCarrierName($deliveryOptionsAdapter->getCarrier()))
->setApiKey($apiKey)
->setReferenceId($shipment->getEntityId())
->setReferenceIdentifier($shipment->getEntityId())
->setConsignmentId($magentoTrack->getData('myparcel_consignment_id'))
->setCountry($address->getCountryId())
->setCompany(self::$defaultOptions->getMaxCompanyName($address->getCompany()))
Expand Down Expand Up @@ -227,13 +227,13 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options)
->setAgeCheck($this->shipmentOptionsHelper->hasAgeCheck())
->setInsurance($this->shipmentOptionsHelper->getInsurance())
->setInvoice(
$magentoTrack->getShipment()
$shipment
->getOrder()
->getIncrementId()
)
->setSaveRecipientAddress(false);

if ($deliveryOptionsAdapter->isPickup()) {
if ($deliveryOptionsAdapter->isPickup() && $pickupLocationAdapter) {
$this->consignment
->setPickupPostalCode($pickupLocationAdapter->getPostalCode())
->setPickupStreet($pickupLocationAdapter->getStreet())
Expand Down
4 changes: 4 additions & 0 deletions Model/Source/DefaultOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function __construct(Order $order, Data $helper)
*/
public function hasDefault(string $option, string $carrier): bool
{
if (AbstractConsignment::SHIPMENT_OPTION_LARGE_FORMAT === $option) {
return $this->hasDefaultLargeFormat($carrier, $option);
}

// Check that the customer has already chosen this option in the checkout
if (is_array(self::$chosenOptions) &&
array_key_exists('shipmentOptions', self::$chosenOptions) &&
Expand Down
6 changes: 3 additions & 3 deletions i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ Track status,Statut du suivi
Track action,Action de suivi
MyParcel options,Options MyParcel
Package,Colis
Signature on receipt,Signature pour réception
Insured up to:,Assuré jusqu'à :
Download package label,Télécharger l'étiquette du colis
Create new concept,Créer une nouveau concept
Expand Down Expand Up @@ -144,8 +143,9 @@ Deliver the package only at address of the intended recipient.,Livraison du coli
This will be added to the regular shipping price,Ceci sera ajouté aux frais d'expédition standards
Not possible if Pickup at PostNL location is not active,Ceci ne sera pas possible si la collecte à un point postnl n'est pas activée
Signature on receipt,Signature pour réception
Signature on receipt title, Signature pour réception - titre
Signature on receipt fee, Signature pour réception - prix
Signature on receipt title,Signature pour réception - titre
Signature on receipt fee,Signature pour réception - prix
Hide sender,Masquer l'expéditeur
This will be added to the regular shipping price, Ceci sera ajouté aux frais d'expédition standards
If both have been selected this price will be added to the regular shipping price. Leave empty for not using it.,Si les deux éléments sont sélectionnés, ce prix sera ajouté aux frais d'expédition standards. Laissez vide pour ignorer cette option.
"To use this optimally, set a weight or 'Fit in mailbox' volume of each product. Regardless, shipments heavier than the weight specified here will not be mailbox.","Pour utiliser cette fonction de manière optimale, spécifiez d'abord le poids ou le volume de vos produits. Les envois plus lourds que le poids spécifié ici ne seront pas considérés comme des envois pour Boîte aux lettres."
Expand Down
6 changes: 3 additions & 3 deletions i18n/nl_NL.csv
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ Track status,Track status
Track action,Track actie
MyParcel options,MyParcel opties
Package,Pakket
Signature on receipt,Handtekening voor ontvangst
Insured up to:,Verzekeren tot:
Download package label,Download pakket label
Download digital stamp label,Download digitalepostzegel label
Expand Down Expand Up @@ -215,8 +214,9 @@ Deliver the package only at address of the intended recipient.,Lever het pakket
This will be added to the regular shipping price,Dit zal bij de normale verzendkosten worden opgeteld
Not possible if Pickup at PostNL location is not active,Dit zal niet mogelijk zijn zodra ophalen bij een PostNL locatie niet geactiveerd is
Signature on receipt,Handtekening voor ontvangst
Signature on receipt title, Handtekening voor ontvangst titel
Signature on receipt fee, Handtekening voor ontvangst kosten
Signature on receipt title,Handtekening voor ontvangst titel
Signature on receipt fee,Handtekening voor ontvangst kosten
Hide sender,Verberg afzender
This will be added to the regular shipping price, Dit zal bij de normale verzendkosten worden opgeteld
If both have been selected this price will be added to the regular shipping price. Leave empty for not using it.,Als beide geselecteerd zijn zal deze prijs bij de normale verzendkosten worden opgeteld. Laat leeg om dit niet te gebruiken.
"To use this optimally, set a weight or 'Fit in mailbox' volume of each product. Regardless, shipments heavier than the weight specified here will not be mailbox.","Om deze functie optimaal te gebruiken, stel je eerst het gewicht of volume in van jouw producten. Ongeacht deze instelling, zendingen zwaarder dan het hier opgegeven gewicht zullen niet als brievenbuspakket worden verzonden."
Expand Down
37 changes: 11 additions & 26 deletions view/adminhtml/templates/new_shipment.phtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/** @var MyParcelNL\Magento\Block\Sales\NewShipment $block */

use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL;
use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;

?>
Expand All @@ -18,7 +19,8 @@ use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
</label>
</div>
<?php
foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments() as $abstractConsignment) {
$form = $block->getNewShipmentForm();
foreach ($form->getCarrierSpecificAbstractConsignments() as $abstractConsignment) {
$abstractConsignment->setCountry($block->getCountry());
$carrier = $abstractConsignment->getCarrier();
$carrierName = $carrier->getName();
Expand Down Expand Up @@ -48,7 +50,7 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
<?php
$country = $block->getCountry();
foreach ($abstractConsignment->getAllowedPackageTypes() as $packageTypeName) {
$packageTypeId = AbstractConsignment::PACKAGE_TYPES_NAMES_IDS_MAP[$packageTypeName];
$packageTypeId = AbstractConsignment::PACKAGE_TYPES_NAMES_IDS_MAP[$packageTypeName];
if (AbstractConsignment::CC_NL !== $country) {
if ($packageTypeId === AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP) {
continue;
Expand All @@ -57,9 +59,7 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
continue;
}
}
$packageTypeHuman = $block->getNewShipmentForm()::PACKAGE_TYPE_HUMAN_MAP[$packageTypeId]
??
$packageTypeName;
$packageTypeHuman = $form::PACKAGE_TYPE_HUMAN_MAP[$packageTypeId] ?? $packageTypeName;
?>
<div class="admin__field admin__field-option">
<input
Expand Down Expand Up @@ -116,13 +116,6 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
?>
</div>

<?php
$carrier = $abstractConsignment->getCarrier();
if (! $carrier) {
continue;
}
$carrierName = $carrier->getName();
?>
<div
class="field choice admin__field admin__field-option field-mypa_label_amount mypa_package-toggle
mypa-option-toggle" style="padding-left: 30px;" data-for_mypa_package_type="<?= $packageTypeName ?>">
Expand All @@ -140,31 +133,24 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
title="">
<?php
while ($label_amount <= 10) {
echo '<option value="' . $label_amount . '" >' . __($label_amount) . '</option>';
echo '<option value="', $label_amount, '" >', __($label_amount), '</option>';
$label_amount++;
}
?>
</select>
</div>
<?php
$isInternational = AbstractConsignment::CC_NL !== $block->getCountry();

try {
$abstractConsignment->setPackageType($packageTypeId);
} catch (\Exception $e) {
continue;
}
foreach ($abstractConsignment->getAllowedShipmentOptions() as $shipmentOption) {
if (
$isInternational
|| AbstractConsignment::SHIPMENT_OPTION_INSURANCE === $shipmentOption
|| ! $abstractConsignment->canHaveShipmentOption($shipmentOption)
if (AbstractConsignment::SHIPMENT_OPTION_INSURANCE === $shipmentOption
FreekVR marked this conversation as resolved.
Show resolved Hide resolved
|| ! $block->consignmentHasShipmentOption($abstractConsignment, $shipmentOption)
) {
continue;
}
$isActive = ($abstractConsignment::SHIPMENT_OPTION_LARGE_FORMAT === $shipmentOption)
? $block->hasDefaultLargeFormat($shipmentOption, $carrier->getName())
: $block->hasDefaultOption($shipmentOption, $carrier->getName());
?>
<div
class="field choice admin__field admin__field-option field-mypa_signature mypa_package-toggle mypa-option-toggle"
Expand All @@ -176,15 +162,14 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
name="mypa_<?= $shipmentOption ?>"
value="1"
type="checkbox"
<?= $isActive
<?= $block->hasDefaultOption($shipmentOption, $carrierName)
? 'checked="checked"'
: '' ?>
/>
<label
class="admin__field-label"
for="mypa_<?= $shipmentOption ?>_<?= $carrierName ?>_<?= $packageTypeId ?>">
<span><?= $block->getNewShipmentForm()
->getShipmentOptionsHumanMap()[$shipmentOption] ?? $shipmentOption ?>
<span><?= $form->getShipmentOptionsHumanMap()[$shipmentOption] ?? $shipmentOption ?>
</span>
</label>
</div>
Expand All @@ -201,7 +186,7 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
<label class="admin__field-label" for="mypa_insurance" style="display: block">
<span><?= __('Insured up to:') ?></span>
</label>
<?php $defaultInsurance = $block->getDefaultInsurance($carrier->getName()); ?>
<?php $defaultInsurance = $block->getDefaultInsurance($carrierName); ?>
<select
name="mypa_insurance"
id="mypa_insurance"
Expand Down