diff --git a/Block/Sales/NewShipment.php b/Block/Sales/NewShipment.php index 6865d32c..1dd48e72 100755 --- a/Block/Sales/NewShipment.php +++ b/Block/Sales/NewShipment.php @@ -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(); diff --git a/Helper/Data.php b/Helper/Data.php index 9cf587f5..aec3ee1a 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -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, @@ -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'); diff --git a/Model/Sales/MagentoOrderCollection.php b/Model/Sales/MagentoOrderCollection.php index d8946182..90b2d382 100755 --- a/Model/Sales/MagentoOrderCollection.php +++ b/Model/Sales/MagentoOrderCollection.php @@ -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; @@ -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; @@ -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; /** @@ -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(); }); @@ -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; @@ -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 { @@ -637,5 +634,4 @@ public function createMagentoShipment(Order $order, bool $notifyClientByEmail = ->notify($shipment); } } - } diff --git a/Model/Sales/Repository/PackageRepository.php b/Model/Sales/Repository/PackageRepository.php index 02b21acb..5edf8f7d 100755 --- a/Model/Sales/Repository/PackageRepository.php +++ b/Model/Sales/Repository/PackageRepository.php @@ -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 @@ -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 diff --git a/Model/Sales/TrackTraceHolder.php b/Model/Sales/TrackTraceHolder.php index 90393fd1..964c8584 100755 --- a/Model/Sales/TrackTraceHolder.php +++ b/Model/Sales/TrackTraceHolder.php @@ -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') @@ -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())); @@ -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( diff --git a/Model/Source/DefaultOptions.php b/Model/Source/DefaultOptions.php index aba489bf..fbf0ee93 100755 --- a/Model/Source/DefaultOptions.php +++ b/Model/Source/DefaultOptions.php @@ -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']) &&