Skip to content

Commit

Permalink
Merge pull request #501 from myparcelnl/MY-25102-weight-calculation-w…
Browse files Browse the repository at this point in the history
…ith-decimal

My 25102 weight calculation with decimal
  • Loading branch information
RichardPerdaan authored Oct 27, 2020
2 parents cb53bb1 + eb1cc06 commit 504ea10
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
27 changes: 9 additions & 18 deletions Model/Sales/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@

namespace MyParcelNL\Magento\Model\Sales;


use Magento\Framework\App\ObjectManager;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\App\Helper\Context;
use Magento\Quote\Api\Data\EstimateAddressInterfaceFactory;
use MyParcelNL\Magento\Helper\Data;
use MyParcelNL\Sdk\src\Services\CheckApiKeyService;
use Psr\Log\LoggerInterface;

class Package extends Data implements PackageInterface
{
Expand Down Expand Up @@ -85,27 +78,27 @@ class Package extends Data implements PackageInterface
private $package_type = null;

/**
* @return int
* @return float
*/
public function getWeight()
{
return $this->weight;
}

/**
* @param $weight
* @param float $weight
*/
public function setWeight(int $weight)
public function setWeight(float $weight)
{
$this->weight = (int) $weight;
$this->weight = $weight;
}

/**
* @param int $weight
* @param float $weight
*/
public function addWeight(int $weight)
public function addWeight(float $weight)
{
$this->weight += (int) $weight;
$this->weight += $weight;
}

/**
Expand All @@ -117,14 +110,13 @@ public function getMaxWeight(): int
}

/**
* @param int $max_weight
* @param float $max_weight
*/
public function setMaxWeight(int $max_weight)
public function setMaxWeight(float $max_weight)
{
$this->max_weight = $max_weight;
}


/**
* @return bool
*/
Expand Down Expand Up @@ -222,7 +214,6 @@ public function setAllProductsFit(bool $all_products_fit)
}
}


/**
* package = 1
*
Expand Down
8 changes: 4 additions & 4 deletions Model/Sales/PackageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
interface PackageInterface
{
/**
* @return int
* @return float
*/
public function getWeight();
/**
* @param $weight
*/
public function setWeight(int $weight);
public function setWeight(float $weight);
/**
* @param int $weight
* @param float $weight
*/
public function addWeight(int $weight);
public function addWeight(float $weight);
/**
* @return bool
*/
Expand Down
4 changes: 2 additions & 2 deletions Model/Sales/TrackTraceHolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private function convertDataForCdCountry($magentoTrack)
$myParcelProduct = (new MyParcelCustomsItem())
->setDescription($product->getName())
->setAmount($product->getQty())
->setWeight($product->getWeight() ?: 1)
->setWeight($this->getWeightTypeOfOption($product->getWeight()) ?: 1)
->setItemValue($this->getCentsByPrice($product->getPrice()))
->setClassification(
(int) $this->getAttributeValue('catalog_product_entity_int', $product['product_id'], 'classification')
Expand All @@ -347,7 +347,7 @@ private function convertDataForCdCountry($magentoTrack)
$myParcelProduct = (new MyParcelCustomsItem())
->setDescription($item->getName())
->setAmount($item->getQty())
->setWeight($this->getWeightTypeOfOption($item->getWeight()))
->setWeight($this->getWeightTypeOfOption($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

0 comments on commit 504ea10

Please sign in to comment.