Skip to content

Commit

Permalink
fix: fix large format issue (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Ernst committed Dec 8, 2023
1 parent eadc13b commit dd98a32
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Block/Sales/NewShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function getDefaultInsurance(string $carrier): int
*/
public function getDigitalStampWeight(): int
{
$weight = $this->dataHelper->getWeightTypeOfOption($this->order->getWeight() ?? 0.0);
$weight = $this->dataHelper->convertToGrams($this->order->getWeight() ?? 0.0);

if (0 === $weight) {
$weight = $this->defaultOptions->getDigitalStampDefaultWeight();
Expand Down
5 changes: 3 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Data extends AbstractHelper
public const XML_PATH_DHLEUROPLUS_SETTINGS = 'myparcelnl_magento_dhleuroplus_settings/';
public const XML_PATH_DHLPARCELCONNECT_SETTINGS = 'myparcelnl_magento_dhlparcelconnect_settings/';
public const XML_PATH_DPD_SETTINGS = 'myparcelnl_magento_dpd_settings/';
public const XML_PATH_LOCALE_WEIGHT_UNIT = 'general/locale/weight_unit';
public const DEFAULT_WEIGHT = 1000;
public const CARRIERS_XML_PATH_MAP = [
CarrierPostNL::NAME => self::XML_PATH_POSTNL_SETTINGS,
Expand Down Expand Up @@ -252,11 +253,11 @@ public function setOrderStatus(int $order_id, string $status): void
/**
* Get the correct weight type
*
* @param string|null $weight
* @param null|float $weight
*
* @return int
*/
public function getWeightTypeOfOption(?string $weight): int
public function convertToGrams(?float $weight): int
{
$weightType = $this->getGeneralConfig('print/weight_indication');

Expand Down
10 changes: 3 additions & 7 deletions Model/Sales/MagentoOrderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace MyParcelNL\Magento\Model\Sales;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\ResourceModel\Order as OrderResource;
Expand All @@ -15,10 +16,10 @@
use MyParcelNL\Magento\Helper\ShipmentOptions;
use MyParcelNL\Magento\Model\Source\DefaultOptions;
use MyParcelNL\Magento\Services\Normalizer\ConsignmentNormalizer;
use MyParcelNL\Sdk\src\Collection\Fulfilment\OrderCollection;
use MyParcelNL\Sdk\src\Collection\Fulfilment\OrderNotesCollection;
use MyParcelNL\Sdk\src\Factory\ConsignmentFactory;
use MyParcelNL\Sdk\src\Factory\DeliveryOptionsAdapterFactory;
use MyParcelNL\Sdk\src\Collection\Fulfilment\OrderCollection;
use MyParcelNL\Sdk\src\Helper\SplitStreet;
use MyParcelNL\Sdk\src\Model\Carrier\CarrierFactory;
use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL;
Expand All @@ -28,8 +29,6 @@
use MyParcelNL\Sdk\src\Model\PickupLocation;
use MyParcelNL\Sdk\src\Model\Recipient;
use MyParcelNL\Sdk\src\Support\Collection;
use Magento\Framework\App\Config\ScopeConfigInterface;
use MyParcelNL\Magento\Model\Sales\TrackTraceHolder;
use MyParcelNL\Sdk\src\Support\Str;

/**
Expand Down Expand Up @@ -319,7 +318,6 @@ private function setMagentoOrdersAsExported(): void
foreach ($this->getOrders() as $magentoOrder) {
$magentoOrder->setData('track_status', UpdateStatus::ORDER_STATUS_EXPORTED);


$fulfilmentOrder = $this->myParcelCollection->first(function(FulfilmentOrder $order) use ($magentoOrder){
return $order->getExternalIdentifier() === $magentoOrder->getIncrementId();
});
Expand Down Expand Up @@ -347,7 +345,7 @@ private function getTotalWeight(): int
continue;
}

$totalWeight += $this->helper->getWeightTypeOfOption((string) ($product->getWeight() * $item->getQtyShipped()));
$totalWeight += $this->helper->convertToGrams($product->getWeight() * $item->getQtyShipped());
}

return $totalWeight;
Expand Down Expand Up @@ -622,7 +620,6 @@ public function createMagentoShipment(Order $order, bool $notifyClientByEmail =
$this->objectManager->get(ShipmentResource::class)->save($shipment);
$this->objectManager->get(OrderResource::class)->save($shipment->getOrder());
} catch (\Exception $e) {

if (preg_match('/' . MagentoOrderCollection::DEFAULT_ERROR_ORDER_HAS_NO_SOURCE . '/', $e->getMessage())) {
$this->messageManager->addErrorMessage(__(MagentoOrderCollection::ERROR_ORDER_HAS_NO_SOURCE));
} else {
Expand All @@ -637,5 +634,4 @@ public function createMagentoShipment(Order $order, bool $notifyClientByEmail =
->notify($shipment);
}
}

}
4 changes: 2 additions & 2 deletions Model/Sales/Repository/PackageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PackageRepository extends Package
{
public const DEFAULT_MAXIMUM_MAILBOX_WEIGHT = 2000;
public const MAXIMUM_DIGITAL_STAMP_WEIGHT = 2000;
public const DEFAULT_LARGE_FORMAT_WEIGHT = 2300;
public const DEFAULT_LARGE_FORMAT_WEIGHT = 23000;

/**
* @var bool
Expand Down Expand Up @@ -128,7 +128,7 @@ public function fitInMailbox(): bool
*/
public function fitInDigitalStamp(): bool
{
$orderWeight = $this->getWeightTypeOfOption($this->getWeight());
$orderWeight = $this->convertToGrams($this->getWeight());
$maximumDigitalStampWeight = $this->getMaxDigitalStampWeight();

return $this->getCurrentCountry() === AbstractConsignment::CC_NL
Expand Down
6 changes: 3 additions & 3 deletions Model/Sales/TrackTraceHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ private function convertDataForCdCountry(Track $magentoTrack)
$myParcelProduct = (new MyParcelCustomsItem())
->setDescription($product->getName())
->setAmount($product->getQty())
->setWeight($this->dataHelper->getWeightTypeOfOption($product->getWeight()) ?: 1)
->setWeight($this->dataHelper->convertToGrams($product->getWeight()) ?: 1)
->setItemValue($this->getCentsByPrice($product->getPrice()))
->setClassification(
(int) $this->getAttributeValue('catalog_product_entity_int', $product['product_id'], 'classification')
Expand All @@ -368,7 +368,7 @@ private function convertDataForCdCountry(Track $magentoTrack)
$myParcelProduct = (new MyParcelCustomsItem())
->setDescription($item->getName())
->setAmount($item->getQty())
->setWeight($this->dataHelper->getWeightTypeOfOption($item->getWeight() * $item->getQty()))
->setWeight($this->dataHelper->convertToGrams($item->getWeight() * $item->getQty()))
->setItemValue($item->getPrice() * 100)
->setClassification((int) $this->getAttributeValue('catalog_product_entity_int', $item->getProductId(), 'classification'))
->setCountry($this->getCountryOfOrigin($item->getProductId()));
Expand Down Expand Up @@ -457,7 +457,7 @@ private function calculateTotalWeight(Track $magentoTrack, int $totalWeight = 0)
$totalWeight += $shipmentItem['weight'] * $shipmentItem['qty'];
}

$totalWeight = $this->dataHelper->getWeightTypeOfOption($totalWeight);
$totalWeight = $this->dataHelper->convertToGrams($totalWeight);

if (0 === $totalWeight) {
throw new \RuntimeException(
Expand Down
2 changes: 1 addition & 1 deletion Model/Source/DefaultOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getMaxCompanyName(?string $company): ?string
public function hasDefaultLargeFormat(string $carrier, string $option): bool
{
$price = self::$order->getGrandTotal();
$weight = self::$order->getWeight();
$weight = self::$helper->convertToGrams(self::$order->getWeight());

$settings = self::$helper->getStandardConfig($carrier, 'default_options');
if (isset($settings[$option . '_active']) &&
Expand Down

0 comments on commit dd98a32

Please sign in to comment.