Skip to content

Commit

Permalink
Merge pull request #90 from engcom-Foxtrot/2.4-dev-php8-sync
Browse files Browse the repository at this point in the history
2.4 dev php8 sync
  • Loading branch information
sivaschenko authored Mar 12, 2021
2 parents d7bfbd4 + febea46 commit c898dbf
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 56 deletions.
11 changes: 9 additions & 2 deletions Inventory/Model/ResourceModel/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Magento\Framework\Model\AbstractModel;
use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
use Magento\Framework\Model\ResourceModel\Db\Context;
use Magento\InventoryApi\Model\SourceCarrierLinkManagementInterface;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\Framework\Model\ResourceModel\PredefinedId;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Model\SourceCarrierLinkManagementInterface;

/**
* Implementation of basic operations for Source entity for specific db layer
Expand Down Expand Up @@ -63,6 +63,12 @@ public function __construct(
protected function _construct()
{
$this->_init(self::TABLE_NAME_SOURCE, SourceInterface::SOURCE_CODE);
$this->addUniqueField(
[
'field' => SourceInterface::NAME,
'title' => 'Name'
]
);
}

/**
Expand All @@ -84,6 +90,7 @@ public function save(AbstractModel $object)
$connection = $this->getConnection();
$connection->beginTransaction();
try {
$object->isObjectNew(!$this->isObjectNotNew($object));
parent::save($object);
/** @var SourceInterface $object */
$this->sourceCarrierLinkManagement->saveCarrierLinksBySource($object);
Expand Down
19 changes: 10 additions & 9 deletions InventoryAdminUi/Controller/Adminhtml/Source/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
use Exception;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Validation\ValidationException;
use Magento\Inventory\Model\Source;
use Magento\InventoryAdminUi\Model\Source\SourceHydrator;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Api\Data\SourceInterfaceFactory;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\InventoryAdminUi\Model\Source\SourceHydrator;
use Magento\Framework\App\Action\HttpPostActionInterface;

/**
* Source save controller.
Expand Down Expand Up @@ -99,15 +100,15 @@ public function execute(): ResultInterface
$this->messageManager->addErrorMessage($localizedError->getMessage());
}
$this->_session->setSourceFormData($requestData);
$this->processRedirectAfterFailureSave($resultRedirect, $sourceCode);
$this->processRedirectAfterFailureSave($resultRedirect, $source);
} catch (CouldNotSaveException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->_session->setSourceFormData($requestData);
$this->processRedirectAfterFailureSave($resultRedirect, $sourceCode);
$this->processRedirectAfterFailureSave($resultRedirect, $source);
} catch (Exception $e) {
$this->messageManager->addErrorMessage(__('Could not save Source.'));
$this->_session->setSourceFormData($requestData);
$this->processRedirectAfterFailureSave($resultRedirect, $sourceCode);
$this->processRedirectAfterFailureSave($resultRedirect, $source);
}
return $resultRedirect;
}
Expand Down Expand Up @@ -177,18 +178,18 @@ private function processRedirectAfterSuccessSave(Redirect $resultRedirect, strin
* Get redirect url after unsuccessful source save.
*
* @param Redirect $resultRedirect
* @param string|null $sourceCode
* @param null|SourceInterface $source
* @return void
*/
private function processRedirectAfterFailureSave(Redirect $resultRedirect, string $sourceCode = null)
private function processRedirectAfterFailureSave(Redirect $resultRedirect, ?SourceInterface $source = null)
{
if (null === $sourceCode) {
if (!$source || $source->isObjectNew()) {
$resultRedirect->setPath('*/*/new');
} else {
$resultRedirect->setPath(
'*/*/edit',
[
SourceInterface::SOURCE_CODE => $sourceCode,
SourceInterface::SOURCE_CODE => $source->getSourceCode(),
'_current' => true,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace Magento\InventoryAdminUi\Test\Integration\Controller\Adminhtml\Source;

use Magento\Framework\App\Request\Http as HttpRequest;
use Magento\Framework\Message\MessageInterface;
use Magento\InventoryAdminUi\Controller\Adminhtml\Source\Save;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\TestFramework\TestCase\AbstractBackendController;
Expand Down Expand Up @@ -54,6 +55,25 @@ public function testExecute(): void
$this->assertEquals('182', $source->getRegionId());
}

/**
* Verify, source will not be saved with name that already exists in database.
*
* @return void
*/
public function testValidateUniqueName(): void
{
$requestData = $this->getRequestData();
$this->getRequest()->setMethod(HttpRequest::METHOD_POST);
$this->getRequest()->setPostValue($requestData);
$this->dispatch('backend/inventory/source/save');
$this->assertSessionMessages($this->isEmpty(), MessageInterface::TYPE_ERROR);
$requestData['general']['source_code'] .= '_new';
$this->getRequest()->setPostValue($requestData);
$this->dispatch('backend/inventory/source/save');
$this->assertSessionMessages($this->equalTo(['Could not save Source']), MessageInterface::TYPE_ERROR);
$this->assertRedirect($this->stringContains('inventory/source/new'));
}

/**
* Data for test.
*
Expand All @@ -62,25 +82,24 @@ public function testExecute(): void
private function getRequestData(): array
{
return [
'general' =>
[
'source_code' => 'test_source_with_region_id_and_region',
'name' => 'Test Source With Region ID And Region',
'latitude' => '',
'longitude' => '',
'contact_name' => '',
'email' => '',
'phone' => '',
'fax' => '',
'region' => 'Ain',
'city' => '',
'street' => '',
'postcode' => '12345',
'enabled' => '1',
'description' => '',
'country_id' => 'FR',
'region_id' => '182',
],
'general' => [
'source_code' => 'test_source_with_region_id_and_region',
'name' => 'Test Source With Region ID And Region',
'latitude' => '',
'longitude' => '',
'contact_name' => '',
'email' => '',
'phone' => '',
'fax' => '',
'region' => 'Ain',
'city' => '',
'street' => '',
'postcode' => '12345',
'enabled' => '1',
'description' => '',
'country_id' => 'FR',
'region_id' => '182',
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<severity value="CRITICAL"/>
<group value="msi"/>
<group value="multi_mode"/>
<skip>
<issueId value="MC-41049"/>
</skip>
</annotations>

<before>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
</annotations>

<before>
<magentoCLI command="config:set {{TurnOnManageStockConfig.path}} {{TurnOnManageStockConfig.value}}" stepKey="enableStockManagement"/>
<!--Create test data.-->
<createData entity="MsiCustomer1" stepKey="customer"/>
<createData entity="FullSource1" stepKey="additionalSource"/>
Expand All @@ -30,21 +31,23 @@
<requiredEntity createDataKey="additionalSource"/>
</createData>
<createData entity="SimpleSubCategory" stepKey="category"/>
<createData entity="GroupedProduct" stepKey="groupedProduct">
<field key="name">CustomGroupedProduct</field>
</createData>
<createData entity="GroupedProduct" stepKey="groupedProduct"/>
<createData entity="SimpleProduct" stepKey="simpleProduct">
<requiredEntity createDataKey="category"/>
</createData>
<createData entity="VirtualProduct" stepKey="virtualProduct">
<requiredEntity createDataKey="category"/>
</createData>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="cleanCache">
<argument name="tags" value=""/>
</actionGroup>
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
</before>
<after>
<!--Disable additional source.-->
<actionGroup ref="DisableSourceActionGroup" stepKey="disableAdditionalSource">
<argument name="sourceCode" value="$$additionalSource.source[source_code]$$"/>
<argument name="sourceCode" value="$additionalSource.source[source_code]$"/>
</actionGroup>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutOfAdmin"/>
<!--Clean up created data.-->
Expand All @@ -57,48 +60,50 @@

<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="openProductGrid2"/>
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterProduct2">
<argument name="product" value="$$groupedProduct$$"/>
<argument name="product" value="$groupedProduct$"/>
</actionGroup>

<actionGroup ref="OpenProductForEditByClickingRowXColumnYInProductGridActionGroup" stepKey="openSecondProductForEdit"/>
<actionGroup ref="AdminAssignProductToGroupActionGroup" stepKey="addFirstSimpleToGroup">
<argument name="product" value="$$simpleProduct$$"/>
<argument name="product" value="$simpleProduct$"/>
</actionGroup>

<actionGroup ref="FillDefaultQuantityForLinkedToGroupProductInGridActionGroup" stepKey="fillDefaultQtyForVirtualProduct1">
<argument name="productName" value="$$simpleProduct.name$$"/>
<argument name="productName" value="$simpleProduct.name$"/>
<argument name="qty" value="2"/>
</actionGroup>

<actionGroup ref="AdminAssignProductToGroupActionGroup" stepKey="addSecondSimpleToGroup">
<argument name="product" value="$$virtualProduct$$"/>
<argument name="product" value="$virtualProduct$"/>
</actionGroup>

<actionGroup ref="FillDefaultQuantityForLinkedToGroupProductInGridActionGroup" stepKey="fillDefaultQtyForVirtualProduct2">
<argument name="productName" value="$$virtualProduct.name$$"/>
<argument name="productName" value="$virtualProduct.name$"/>
<argument name="qty" value="2"/>
</actionGroup>

<selectOption selector="{{AdminProductFormBundleSection.stockStatusField}}" userInput="Out of Stock" stepKey="stockStatus"/>

<scrollToTopOfPage stepKey="scrollOnTopOfProductPagePage"/>
<actionGroup ref="AdminAssignCategoryToProductAndSaveActionGroup" stepKey="assignCategoryToProduct">
<argument name="categoryName" value="$$category.name$$"/>
<argument name="categoryName" value="$category.name$"/>
</actionGroup>

<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStoreFrontHomePage"/>
<actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="quickSearchByProductName">
<argument name="phrase" value="$$groupedProduct.sku$$"/>
<argument name="phrase" value="$groupedProduct.name$"/>
</actionGroup>
<dontSee userInput="$$groupedProduct.name$$" stepKey="verifyProductNotPresentOnStorefront"/>
<dontSee selector="{{StorefrontCatalogSearchMainSection.searchResults}}" userInput="$groupedProduct.name$" stepKey="verifyProductNotPresentOnStorefront"/>
<magentoCLI command="config:set {{TurnOffManageStockConfig.path}} {{TurnOffManageStockConfig.value}}" stepKey="manageStockToNo"/>
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
<magentoCLI command="cache:flush" stepKey="flushCache"/>
<actionGroup ref="CliCacheCleanActionGroup" stepKey="flushCache">
<argument name="tags" value=""/>
</actionGroup>

<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="openStoreFrontHomePage2"/>
<actionGroup ref="StorefrontCheckQuickSearchStringActionGroup" stepKey="quickSearchByProductName2">
<argument name="phrase" value="$$groupedProduct.sku$$"/>
<argument name="phrase" value="$groupedProduct.name$"/>
</actionGroup>
<see userInput="$$groupedProduct.name$$" stepKey="verifyProductPresentOnStorefront"/>
<see selector="{{StorefrontCatalogSearchMainSection.searchResults}}" userInput="$groupedProduct.name$" stepKey="verifyProductPresentOnStorefront"/>
</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<severity value="CRITICAL"/>
<group value="msi"/>
<group value="multi_mode"/>
<skip>
<issueId value="MC-41048"/>
</skip>
</annotations>

<before>
Expand Down Expand Up @@ -168,4 +171,3 @@
<dontSee selector="{{AdminProductGridSection.productQtyPerSource('4', $$createFourthCustomSource.source[name]$$)}}" userInput="0" stepKey="checkSourceQtyForFourthCreatedProductForFourthSourceUnassined"/>
</test>
</tests>

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Magento\InventoryConfigurableProduct\Plugin\Model\ResourceModel\Attribute;

use Magento\CatalogInventory\Api\StockConfigurationInterface;
use Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
Expand Down Expand Up @@ -43,23 +44,32 @@ class IsSalableOptionSelectBuilder
*/
private $defaultStockProvider;

/**
* @var StockConfigurationInterface
*/
private $stockConfig;

/**
* @param StoreManagerInterface $storeManager
* @param StockResolverInterface $stockResolver
* @param StockIndexTableNameResolverInterface $stockIndexTableNameResolver
* @param DefaultStockProviderInterface $defaultStockProvider
* @param DefaultStockProviderInterface|null $defaultStockProvider
* @param StockConfigurationInterface|null $stockConfig
*/
public function __construct(
StoreManagerInterface $storeManager,
StockResolverInterface $stockResolver,
StockIndexTableNameResolverInterface $stockIndexTableNameResolver,
DefaultStockProviderInterface $defaultStockProvider = null
DefaultStockProviderInterface $defaultStockProvider = null,
StockConfigurationInterface $stockConfig = null
) {
$this->storeManager = $storeManager;
$this->stockResolver = $stockResolver;
$this->stockIndexTableNameResolver = $stockIndexTableNameResolver;
$this->defaultStockProvider = $defaultStockProvider ?: ObjectManager::getInstance()
->get(DefaultStockProviderInterface::class);
$this->stockConfig = $stockConfig ?: ObjectManager::getInstance()
->get(StockConfigurationInterface::class);
}

/**
Expand All @@ -85,14 +95,16 @@ public function afterGetSelect(
}
$stockTable = $this->stockIndexTableNameResolver->execute($stockId);

$select->joinInner(
['stock' => $stockTable],
'stock.sku = entity.sku',
[]
)->where(
'stock.is_salable = ?',
1
);
if (!$this->stockConfig->isShowOutOfStock()) {
$select->joinInner(
['stock' => $stockTable],
'stock.sku = entity.sku',
[]
)->where(
'stock.is_salable = ?',
1
);
}

return $select;
}
Expand Down
Loading

0 comments on commit c898dbf

Please sign in to comment.