Skip to content
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

Conversation

novikor
Copy link
Contributor

@novikor novikor commented May 18, 2019

Description (*)

Added the next fields:

  • Frontend Name
  • Frontend Description (wysiwyg field, label is not shown in BO)
  • Implemented admin UI for them;
  • Refactored some code;

Fixed Issues (if relevant)

  1. Source Entity expansion with Pickup Location attributes #2182:Source Entity expansion with Pickup Location attributes

Manual testing scenarios (*)

  1. Go to source edit page
  2. Make sure pickup location fieldset is not visible until the source is used in the store pickup
  3. Check that new fields are present
  4. Make sure you are able to save them

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

al.kravchuk and others added 7 commits April 16, 2019 18:00
Add rows and extension attributes to Source.
…ce-Entity-expansion-with-Pickup-Location-attributes
Frontend name and frontend description admin UI.
Some refactoring.
Show/Hide the pickup location fieldset depending from `is_pickup_location_active` value
@@ -0,0 +1,54 @@
<?php
Copy link
Contributor

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?

Copy link
Contributor Author

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()
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

Copy link
Contributor Author

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.

@novikor
Copy link
Contributor Author

novikor commented May 20, 2019

TODO: parse FrontendDescription WYSIWYG content while creating pickup location.
See Magento\Widget\Model\Template\Filter

@novikor
Copy link
Contributor Author

novikor commented May 21, 2019

@ishakhsuvarov , - the PR is not ready yet.
@swnsma is going to implement a chain of responsibility for the pickup location mapper,
and I will reuse this logic then

…ce-Entity-expansion-with-Pickup-Location-attributes
Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a 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
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitPickupLocationExtensionAttributes ?

}

/**
* Enrich the given Source Objects with the In-Store pickup attribute
*
* @param SourceRepositoryInterface $subject
* @param SourceInterface $source
* @param SourceInterface|DataObject $source
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

al.kravchuk and others added 2 commits May 22, 2019 14:35
Refactor Pickup Locations mapper.
Add possibility to pre-process Source data for projection to Pickup Location.
LocalizedException -> InvalidArgumentException
@novikor novikor force-pushed the MSI-2182-Source-Entity-expansion-with-Pickup-Location-attributes branch from 2aa38ff to f57691c Compare May 23, 2019 10:05
Maksym Novik added 2 commits May 23, 2019 13:43
If frontend name is empty, pickup location uses source regular name now.
@novikor novikor force-pushed the MSI-2182-Source-Entity-expansion-with-Pickup-Location-attributes branch from 17ca2eb to e276996 Compare May 23, 2019 11:44
Maksym Novik and others added 2 commits May 23, 2019 15:17
Some refactoring: added explicit DataObject check
…ce-Entity-expansion-with-Pickup-Location-attributes
@novikor
Copy link
Contributor Author

novikor commented May 28, 2019

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
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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
{

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an empty line

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

@novikor novikor May 30, 2019

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@ishakhsuvarov ishakhsuvarov merged commit cd0b5db into store-pickup Jun 5, 2019
@ghost
Copy link

ghost commented Jun 5, 2019

Hi @novikor, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@ishakhsuvarov ishakhsuvarov deleted the MSI-2182-Source-Entity-expansion-with-Pickup-Location-attributes branch June 19, 2019 16:16
@ishakhsuvarov ishakhsuvarov removed this from the Store Pickup Support milestone Sep 10, 2019
ishakhsuvarov added a commit that referenced this pull request Nov 22, 2019
…xpansion-with-Pickup-Location-attributes

Msi 2182 source entity expansion with pickup location attributes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants