-
Notifications
You must be signed in to change notification settings - Fork 247
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
Msi 2182 source entity expansion with pickup location attributes #2267
Msi 2182 source entity expansion with pickup location attributes #2267
Conversation
Add rows and extension attributes to Source.
…ce-Entity-expansion-with-Pickup-Location-attributes
open_hours -> frontend_description
Frontend name and frontend description admin UI. Some refactoring.
Improved tests coverage
Show/Hide the pickup location fieldset depending from `is_pickup_location_active` value
Adjusted Pickup Location entity
@@ -0,0 +1,54 @@ | |||
<?php |
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.
There is already fixture to make source -> pickup location: app/code/Magento/InventoryInStorePickup/Test/_files/source_pickup_location_attributes.php
Do we really need extra 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.
Yes
@@ -85,86 +88,25 @@ public function testWrongMappingForPickupLocation() | |||
} | |||
|
|||
/** | |||
* @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source.php | |||
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/pickup_location.php | |||
*/ | |||
public function testMapPickupLocation() |
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.
What about case:
Source.ExtensionAttributes.Field1 -> PickupLocation.ExtensionAttributes.Field2
?
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.
Why did you not cover it before?)
Okay, I`ll check
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.
@swnsma , I afraid it is out of scope. Feel free to do it by yourself.
Fixed static tests
Set frontend name default value.
TODO: parse |
@ishakhsuvarov , - the PR is not ready yet. |
…ce-Entity-expansion-with-Pickup-Location-attributes
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.
Whole mechanism of working with specific fields of SourceInteface
via DataObject
implementation does not seem correct.
Should we research additional ways? Something cleaner like a Resource maybe? Or maybe you have more approaches on your mind?
$this->extensionAttributesFactory = $extensionAttributesFactory; | ||
} | ||
/** | ||
* @param SourceInterface|DataObject $source |
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.
Let's keep doc block and contract consistent
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.
Done
/** | ||
* Set store-pickup related source extension attributes | ||
*/ | ||
class SetExtensionAttributes |
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.
Class name seems to abstract
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.
InitPickupLocationExtensionAttributes
?
app/code/Magento/InventoryInStorePickup/Model/Source/SetExtensionAttributes.php
Outdated
Show resolved
Hide resolved
} | ||
|
||
/** | ||
* Enrich the given Source Objects with the In-Store pickup attribute | ||
* | ||
* @param SourceRepositoryInterface $subject | ||
* @param SourceInterface $source | ||
* @param SourceInterface|DataObject $source |
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.
That's cheating. We can't typehint for SourceInterface and rely on Dataobject in reality
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.
Fixed
use Magento\InventoryApi\Api\Data\SourceInterface; | ||
use Magento\InventoryApi\Api\SourceRepositoryInterface; | ||
use Magento\InventoryInStorePickupApi\Api\Data\PickupLocationInterface as Location; | ||
|
||
class SaveInStorePickupPlugin |
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.
Let's add description while we are here
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.
Done
Refactor Pickup Locations mapper. Add possibility to pre-process Source data for projection to Pickup Location.
LocalizedException -> InvalidArgumentException
2aa38ff
to
f57691c
Compare
If frontend name is empty, pickup location uses source regular name now.
Fixed jscs tests
17ca2eb
to
e276996
Compare
Some refactoring: added explicit DataObject check
…ce-Entity-expansion-with-Pickup-Location-attributes
Reminder for myself: display Frontend Description label |
@@ -47,28 +48,49 @@ public function __construct( | |||
* @inheritdoc | |||
* @throws \InvalidArgumentException | |||
*/ | |||
public function execute(SourceInterface $source, array $map): PickupLocationInterface | |||
public function execute(SourceInterface $source, array $map, array $preProcessors): PickupLocationInterface |
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.
Why preProcessors
aren't constructor injection? Adequate type checking and hinting is missing as well.
Edit: Would be resolved in a different PR after additional discussion
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.
Well.
What about creating something kind of PreProcessorsList
(like RouterList
), mark it as @api
and inject into constructor then?
* | ||
* @return mixed | ||
*/ | ||
public function process(SourceInterface $source, $value); |
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.
Situation where mixed
type have to be used may be a hint to a non-optimal design.
In this case, this contract seems incomplete, as Field Name seems to be hardcoded somewhere in the implementation and value has to be mixed.
I also love single responsibility classes, but still, it may be an overkill to introduce a class per field.
|
||
class FrontendName implements PreProcessorInterface | ||
{ | ||
|
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.
Just an empty line
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.
That`s really horrible
if (!$source instanceof DataObject) { | ||
return; | ||
} | ||
$pickupAvailable = $source->getData(PickupLocationInterface::IS_PICKUP_LOCATION_ACTIVE); |
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.
In the last review I wasn't clear enough.
Just wanted to make sure that this is the best idea we have to load newly introduced fields.
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.
Well, we could do some magic with converting snake_case field name to camelCase, check if the appropriate getter method exists and then call it...
But I don`t like this idea :)
public function __construct( | ||
InitPickupLocationExtensionAttributes $setExtensionAttributes | ||
) { | ||
$this->setExtensionAttributes = $setExtensionAttributes; |
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.
While this seems to be an excessive extraction, it seems to be the bet solution if we don't figure out to load data in a better way.
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.
Well, as a variant, it probably would be nice to extract this logic into a chain of responsibility.
…h-Pickup-Location-attributes
Hi @novikor, thank you for your contribution! |
…xpansion-with-Pickup-Location-attributes Msi 2182 source entity expansion with pickup location attributes
Description (*)
Added the next fields:
Fixed Issues (if relevant)
Manual testing scenarios (*)
Contribution checklist (*)