-
Notifications
You must be signed in to change notification settings - Fork 248
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
Mni/source selection #33
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Inventory\Model; | ||
|
||
class Package extends \Magento\Framework\Api\AbstractExtensibleObject | ||
implements PackageInterface | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getSource() | ||
{ | ||
return $this->_get('source'); | ||
} | ||
|
||
public function getQty() | ||
{ | ||
return $this->_get('qty'); | ||
} | ||
|
||
public function setAddress($address) | ||
{ | ||
return $this->_set('address', $address); | ||
} | ||
|
||
public function getAddress() | ||
{ | ||
return $this->_get('address'); | ||
} | ||
|
||
/** | ||
* @return \Magento\Quote\Model\Quote\Item[] | ||
*/ | ||
public function getItems() | ||
{ | ||
return $this->_get('items'); | ||
} | ||
|
||
public function getBaseSubtotal() | ||
{ | ||
return $this->_get('base_subtotal'); | ||
} | ||
|
||
public function getBaseSubtotalWithDiscount() | ||
{ | ||
return $this->_get('base_subtotal_with_discount'); | ||
} | ||
|
||
public function getWeight() | ||
{ | ||
return $this->_get('weight'); | ||
} | ||
|
||
public function getItemQty() | ||
{ | ||
return $this->_get('item_qty'); | ||
} | ||
|
||
public function getPhysicalValue() | ||
{ | ||
return $this->_get('physical_value'); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Inventory\Model; | ||
|
||
interface PackageInterface | ||
{ | ||
/** | ||
* @return \Magento\InventoryApi\Api\Data\SourceInterface | ||
*/ | ||
public function getSource(); | ||
|
||
/** | ||
* @return \Magento\Quote\Model\Quote\Item[] | ||
*/ | ||
public function getItems(); | ||
|
||
/** | ||
* @return \Magento\Quote\Model\Quote\Address | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be Magento\Quote\Api\Data\AddressInterface |
||
*/ | ||
public function getAddress(); | ||
|
||
/** | ||
* @param $address \Magento\Quote\Model\Quote\Address | ||
* @return $this | ||
*/ | ||
public function setAddress($address); | ||
|
||
public function getQty(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need qty here as it is already part of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, because qty here is the number of the product in this particular package. It can be less or equal to the qty of the product in the cart. I.e. 10 products with sku1 were requested, 6 fulfilled from source 1, 4 from source 2. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't it make sense to just have different quote items in different packages? As it is already implemented even in the current version of the Shipping Assignments Duplication of the Qty in multiple places leads to complicated code which would be potentially hard to maintain There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree with @ishakhsuvarov here. So, it's hard to maintain and keep in consistent state. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's why I proposed to consider usage of Visitor pattern here, |
||
|
||
public function getBaseSubtotal(); | ||
|
||
public function getBaseSubtotalWithDiscount(); | ||
|
||
public function getWeight(); | ||
|
||
public function getItemQty(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between Qty and ItemQuantity? |
||
|
||
public function getPhysicalValue(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is business data represented with this Interface method? PhysicalValue of the package? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Inventory\Model; | ||
|
||
use \Magento\Framework\App\Config\ScopeConfigInterface; | ||
use \Magento\Sales\Model\Order\Shipment; | ||
|
||
class SourceSelection implements SourceSelectionInterface | ||
{ | ||
/** @var PackageFactory */ | ||
private $packageFactory; | ||
|
||
/** @var SourceFactory */ | ||
private $sourceFactory; | ||
|
||
/** @var ScopeConfigInterface */ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @param PackageFactory $packageFactory | ||
* @param SourceFactory $sourceFactory | ||
* @param ScopeConfigInterface $scopeConfig | ||
*/ | ||
public function __construct( | ||
PackageFactory $packageFactory, | ||
SourceFactory $sourceFactory, | ||
ScopeConfigInterface $scopeConfig | ||
) { | ||
$this->packageFactory = $packageFactory; | ||
$this->sourceFactory = $sourceFactory; | ||
$this->scopeConfig = $scopeConfig; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getPackages($store, $items, $destinationAddress) | ||
{ | ||
$countryId = $this->scopeConfig->getValue( | ||
Shipment::XML_PATH_STORE_COUNTRY_ID, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, | ||
$store | ||
); | ||
$regionId = $this->scopeConfig->getValue( | ||
Shipment::XML_PATH_STORE_REGION_ID, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, | ||
$store | ||
); | ||
$city = $this->scopeConfig->getValue( | ||
Shipment::XML_PATH_STORE_CITY, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, | ||
$store | ||
); | ||
$postcode = $this->scopeConfig->getValue( | ||
Shipment::XML_PATH_STORE_ZIP, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, | ||
$store | ||
); | ||
|
||
$source = $this->sourceFactory->create( | ||
[ | ||
'data' => [ | ||
'source_id' => 0, | ||
'name' => 'Default', | ||
'country_id' => $countryId, | ||
'region_id' => $regionId, | ||
'city' => $city, | ||
'postcode' => $postcode | ||
] | ||
] | ||
); | ||
return [ | ||
$this->packageFactory->create( | ||
[ | ||
'data' => [ | ||
'items' => $items, | ||
'source' => $source, | ||
'address' => $destinationAddress | ||
] | ||
] | ||
) | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Inventory\Model; | ||
|
||
interface SourceSelectionInterface | ||
{ | ||
/** | ||
* @param $store | ||
* @param $items | ||
* @param \Magento\Quote\Model\Quote\Address $destinationAddress | ||
* @return Package[] | ||
*/ | ||
public function getPackages($store, $items, $destinationAddress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we accept $store parameter here? in any case if we want introduce scoping , which we usually not do - it should be called $scope , but not $store. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this method supposed to be called several times in case of multi-shipping delivery? |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,18 @@ public function getItems(); | |
*/ | ||
public function setItems($value); | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest refactoring this interface in case we are already introducing BiC, as it does not reflect the desired state described in the latest version of the Multishipping design There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, let me see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We had a discussion regarding implementation of the Visitor pattern to integrate MSI with Quote. Maybe it is better to research that solution? |
||
/** | ||
* @param \Magento\Inventory\Model\PackageInterface[] | ||
* @return $this | ||
*/ | ||
public function setPackages($packages); | ||
|
||
/** | ||
* @return \Magento\Inventory\Model\PackageInterface[] | ||
*/ | ||
public function getPackages(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again ShippingAssignment interface has get/setQuoteItems There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moreover there is a get/setShipping method here which returns |
||
|
||
/** | ||
* Retrieve existing extension attributes object or create a new one. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we no need to return SourceInterface in this interface, because Package can't contain the whole Source entity, it's not an Aggregate Root for the source.
What it can contain is a reference to SourceId.