Skip to content

Commit

Permalink
Msi 2182 source entity expansion with pickup location attributes.
Browse files Browse the repository at this point in the history
If frontend name is empty, pickup location uses source regular name now.
  • Loading branch information
Maksym Novik committed May 23, 2019
1 parent f57691c commit 3b64018
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function execute(SourceInterface $source, array $map, array $preProcessor
private function preProcessData(SourceInterface $source, array $data, array $preProcessors)
{
foreach ($preProcessors as $field => $processor) {
if (isset($data[$field])) {
if (array_key_exists($field, $data)) {
$data[$field] = $processor->process($source, $data[$field]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\InventoryInStorePickup\Model\PickupLocation\Mapper\PreProcessor;

use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryInStorePickupApi\Model\Mapper\PreProcessorInterface;

class FrontendName implements PreProcessorInterface
{

/**
* Process Source Field before pass it to Pickup Location
*
* @param SourceInterface $source
* @param string $value Frontend Name Extension Attribute value
*
* @return string
*/
public function process(SourceInterface $source, $value): string
{
if (empty($value)) {
$value = $source->getName();
}

return $value;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ public function testMapPickupLocation()
$this->assertInstanceOf(PickupLocationExtensionInterface::class, $pickupLocation->getExtensionAttributes());
}

/**
* @magentoDataFixture ../../../../app/code/Magento/InventoryInStorePickup/Test/_files/pickup_location.php
* @throws
*/
public function testEmptyFrontendName()
{
$source = $this->sourceRepository->get($this->sourceCode);
$source->getExtensionAttributes()->setFrontendName(null);

/** @var Mapper $mapper */
$mapper = $this->objectManager->create(Mapper::class);

$pickupLocation = $mapper->map($source);
$this->assertEquals($source->getName(), $pickupLocation->getName());
}

/**
* @return array
*/
Expand Down
7 changes: 3 additions & 4 deletions app/code/Magento/InventoryInStorePickup/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@
<item name="extension_attributes.frontend_name" xsi:type="string">name</item>
<item name="extension_attributes.frontend_description" xsi:type="string">description</item>
</argument>
<argument name="preProcessors" xsi:type="array">
<item name="extension_attributes.frontend_name" xsi:type="object">Magento\InventoryInStorePickup\Model\PickupLocation\Mapper\PreProcessor\FrontendName</item>
</argument>
</arguments>
</type>
<type name="Magento\InventoryApi\Model\SourceValidatorChain">
<plugin name="store-pickup-set-frontend-name"
type="Magento\InventoryInStorePickup\Plugin\InventoryApi\SourceValidatorChain\SetFrontendName" />
</type>
<type name="Magento\InventoryInStorePickup\Model\SourceSelection\GetActiveStorePickupOrdersBySource">
<arguments>
<argument name="statesToFilter" xsi:type="array">
Expand Down

0 comments on commit 3b64018

Please sign in to comment.