-
Notifications
You must be signed in to change notification settings - Fork 253
Msi source export #147
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 source export #147
Conversation
…2 into msi-source-export
…o msi-source-export
@@ -0,0 +1,40 @@ | |||
<?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.
Please pay attention that Travis builds are red.
There is a failure in Static Tests - https://travis-ci.org/magento-engcom/msi/jobs/294045656
$quantityAttribute->setBackendType('decimal'); | ||
$quantityAttribute->setDefaultFrontendLabel(SourceItemInterface::QUANTITY); | ||
$quantityAttribute->setAttributeCode(SourceItemInterface::QUANTITY); | ||
$this->_attributeCollection->addItem($quantityAttribute); |
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 move this Attribute Collection building process into the separate class.
Doing so we will improve Single Responsibility as well as will introduce additional extension point for Attribute Collection building.
Thus, if 3rd party developer would like to inject additional attribute or provide own collection of attributes with filters he suppose to overwrite just this Builder
|
||
/** | ||
* @inheritdoc | ||
* @throws \Exception |
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.
do we really throw an Exception out of this method?
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.
Exception is thrown by an internal method.
* Export process | ||
* | ||
* @return string | ||
* @throws \Magento\Framework\Exception\LocalizedException |
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.
looks like there is no throwing of \Magento\Framework\Exception\LocalizedException
out of current function
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 previouse implementation this exception was thrown by an internal method. In current implementation the method really thow this exception by it self.
} | ||
|
||
/** | ||
* Export process |
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.
please provide a more meaningful description. As I suppose current function is the main for the exporting process
$this->$filterMethodName($collection, $columnName, $value); | ||
} else { | ||
$this->applyDefaultFilter($collection, $columnName, $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.
Try to avoid dynamic PHP behavior, as it most of the time leads to some magic under the hood and bugs which are really hard to debug.
What we usually do in similar cases when there are some processors (with the same contract/interfaces) and depending on the type given you need to apply specific one - we apply Strategy Pattern
In your case that will look like:
interface FilterProcessorInterface
{
public function process($collection, $columnName, $value);
}
class FilterProcessorAggregator
{
// accept an array configured through the DI
// ['handler' => 'filter/handler/class']
// 'filter/handler/class' must be an instance of FilterProcessorInterface
public function __construct($filterHandlers)
// $type is one of the possible handlers Int|String|Decimal|etc
public function process($type, $collection, $columnName, $value)
{
if (!isset($this->hadlers[$type])) {
throw new Exception();
}
$this->hadlers[$type]->process($collection, $columnName, $value);
}
}
you have a dedicated class for each filter
class IntFilter implements FilterProcessorInterface
class StringFilter implements FilterProcessorInterface
class DecimalFilter implements FilterProcessorInterface
after these changes, your business logic will include just FilterProcessorAggregator instance.
and you will call:
$this->filterProcessor->($type, $collection, $columnName, $value);
Also that will give us an ability to easily add new processors later
$to = $value[1] ?? null; | ||
|
||
if (is_scalar($from) && !empty($from)) { | ||
$date = (new \DateTime($from))->format('m/d/Y'); |
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.
better not to use DateTime object directly
but Magento\Framework\Stdlib\DateTime instead
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_ImportExport:etc/export.xsd"> | ||
<entity name="stock_sources" label="Stock Sources" model="Magento\InventoryImportExport\Model\Export\Sources" entityAttributeFilterType="stock_sources"/> | ||
</config> |
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.
additional blank line should be added at the end
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
} | ||
} | ||
|
||
/** |
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.
Both of these refactoring applied will help you to decrease the number of external dependencies for this class
As currently we have a failure in Static Tests:
The class Sources has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13.
*/ | ||
interface SourceItemCollectionFactoryInterface | ||
{ | ||
/** |
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.
Please provide a description of what this Factory creates
*/ | ||
interface FilterProcessorInterface | ||
{ | ||
/** |
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.
please provide a description of the Filter Processing in comment
/** | ||
* @param AttributeCollection $attributeCollection | ||
* @param array $filters | ||
* @return array |
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.
you can use @inheritdoc
if you don't change the comment in the implementation
$to = $value[1] ?? null; | ||
|
||
if (is_scalar($from) && !empty($from)) { | ||
$date = (new \DateTime($from))->format('m/d/Y'); |
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.
you are still using new \DateTime
but not Magento\Framework\Stdlib\DateTime
Fantastic contribution!! Thanks, guys @vadimjustus and @larsroettig This contribution really matters! |
Description
Provides export functionality for Stock Sources
Manual testing scenarios
System > Export
in Magento backendStock Sources
as entity typeContribution checklist