Skip to content

Commit

Permalink
feat: allow exporting digital stamp (#716)
Browse files Browse the repository at this point in the history
  • Loading branch information
joerivanveen authored Oct 4, 2022
1 parent 6dc37e2 commit 793e78c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
27 changes: 15 additions & 12 deletions Block/Sales/NewShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

class NewShipment extends AbstractItems
{
/**
* @var \MyParcelNL\Magento\Helper\Data
*/
private $dataHelper;

/**
* @var \Magento\Sales\Model\Order
*/
Expand All @@ -51,7 +56,7 @@ class NewShipment extends AbstractItems
/**
* @var \MyParcelNL\Magento\Model\Sales\MagentoOrderCollection
*/
private MagentoOrderCollection $orderCollection;
private $orderCollection;

/**
* @var mixed
Expand All @@ -67,13 +72,15 @@ class NewShipment extends AbstractItems
*/
public function __construct(
Context $context,
Data $helper,
StockRegistryInterface $stockRegistry,
StockConfigurationInterface $stockConfiguration,
Registry $registry,
ObjectManagerInterface $objectManager
) {
// Set order
$this->order = $registry->registry('current_shipment')->getOrder();
$this->dataHelper = $helper;
$this->objectManager = $objectManager;
$this->form = new NewShipmentForm();

Expand Down Expand Up @@ -141,7 +148,13 @@ public function getDefaultInsurance(string $carrier): int
*/
public function getDigitalStampWeight(): int
{
return $this->defaultOptions->getDigitalStampDefaultWeight();
$weight = $this->dataHelper->getWeightTypeOfOption($this->order->getWeight() ?? 0.0);

if (0 === $weight) {
$weight = $this->defaultOptions->getDigitalStampDefaultWeight();
}

return $weight;
}

/**
Expand All @@ -160,16 +173,6 @@ public function getCountry()
return $this->order->getShippingAddress()->getCountryId();
}

/**
* Get all chosen options
*
* @return array
*/
public function getChosenOptions()
{
return json_decode($this->order->getData(Checkout::FIELD_DELIVERY_OPTIONS), true);
}

/**
* @return \MyParcelNL\Magento\Block\Sales\NewShipmentForm
*/
Expand Down
2 changes: 1 addition & 1 deletion Model/Sales/TrackTraceHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private function calculateTotalWeight(Track $magentoTrack, int $totalWeight = 0)
return $this;
}

$shipmentItems = $magentoTrack->getShipment()->getData('items');
$shipmentItems = $magentoTrack->getShipment()->getItems();

foreach ($shipmentItems as $shipmentItem) {
$totalWeight += $shipmentItem['weight'] * $shipmentItem['qty'];
Expand Down
12 changes: 6 additions & 6 deletions view/adminhtml/templates/new_shipment.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
<?php
if (AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP === $packageTypeId) {
$weight = $block->getDigitalStampWeight(); ?>
<span data-for_mypa_package_type="<?= $packageTypeName ?>">
<span data-for_mypa_package_type="<?= $packageTypeName ?>" data-weight="<?= $weight ?>">
<select
name="mypa_digital_stamp_weight"
id="mypa_digital_stamp_weight_<?= $carrierName ?>"
Expand All @@ -83,27 +83,27 @@ foreach ($block->getNewShipmentForm()->getCarrierSpecificAbstractConsignments()
title="">
<option value="0">No standard weight</option>
<option
value="20" <?= '20' === $weight
value="20" <?= 20 >= $weight
? 'selected="selected"'
: '' ?> >0 - 20 gram
</option>
<option
value="50" <?= '50' === $weight
value="50" <?= 50 >= $weight && 20 < $weight
? 'selected="selected"'
: '' ?> >20 - 50 gram
</option>
<option
value="100" <?= '100' === $weight
value="100" <?= 100 >= $weight && 50 < $weight
? 'selected="selected"'
: '' ?> >50 - 100 gram
</option>
<option
value="350" <?= '350' === $weight
value="350" <?= 350 >= $weight && 100 < $weight
? 'selected="selected"'
: '' ?> >100 - 350 gram
</option>
<option
value="2000" <?= '2000' === $weight
value="2000" <?= 2000 >= $weight && 350 < $weight
? 'selected="selected"'
: '' ?> >350 - 2000 gram
</option>
Expand Down

0 comments on commit 793e78c

Please sign in to comment.