Skip to content

Commit

Permalink
Added MerchantProductImport functionality cleaned up from redundant l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
mantasmuliar committed Aug 28, 2024
1 parent f02e34c commit eebc286
Show file tree
Hide file tree
Showing 61 changed files with 2,254 additions and 467 deletions.
20 changes: 19 additions & 1 deletion config/Zed/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,28 @@
<product-merchant-portal-gui>
<label>Products</label>
<title>Products</title>
<icon>products</icon>
<icon>offers</icon>
<bundle>product-merchant-portal-gui</bundle>
<controller>products</controller>
<action>index</action>
<pages>
<products>
<label>Products</label>
<title>Products</title>
<bundle>product-merchant-portal-gui</bundle>
<controller>products</controller>
<action>index</action>
<visible>1</visible>
</products>
<import-uploads>
<label>Import History</label>
<title>Import History</title>
<bundle>merchant-product-import-merchant-portal-gui</bundle>
<controller>imports</controller>
<action>index</action>
<visible>1</visible>
</import-uploads>
</pages>
</product-merchant-portal-gui>
<agent-dashboard-merchant-portal-gui>
<label>Merchant Users</label>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* This file is part of the Spryker Commerce OS.
* For full license information, please view the LICENSE file that was distributed with this source code.
*/

namespace Pyz\Shared\MerchantProductImport;

interface MerchantProductImportConstants
{
public const IMPORT_UPLOAD_READ_LIMIT = 'MERCHANT_PRODUCT_IMPORT:IMPORT_UPLOAD_READ_LIMIT';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0"?>
<transfers xmlns="spryker:transfer-01"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="spryker:transfer-01 http://static.spryker.com/transfer-01.xsd">

<transfer name="ImportUpload" strict="true">
<property name="idImportUpload" type="int"/>
<property name="fkMerchant" type="int"/>
<property name="fkUser" type="int"/>
<property name="status" type="string"/>
<property name="numberOfProducts" type="int"/>
<property name="totalNumberOfProducts" type="int"/>
<property name="numberOfProductsFailed" type="int"/>
<property name="numberOfProductsUploaded" type="int"/>
<property name="errors" type="string"/>
<property name="createdAt" type="string"/>
<property name="statusUpdatedAt" type="string"/>
<property name="startedAt" type="string"/>
<property name="finishedAt" type="string"/>
<property name="originalFileName" type="string"/>
<property name="merchant" type="Merchant"/>
<property name="user" type="User"/>
<property name="fileUpload" type="FileUpload"/>
</transfer>

<transfer name="ImportUploadCollection">
<property name="importUploads" type="ImportUpload[]" singular="importUpload"/>
<property name="pagination" type="Pagination"/>
</transfer>

<transfer name="ImportUploadCriteria">
<property name="importUploadConditions" type="ImportUploadConditions"/>
<property name="pagination" type="Pagination"/>
<property name="sortCollection" type="Sort[]" singular="sort"/>
</transfer>

<transfer name="ImportUploadConditions">
<property name="idImportUpload" type="int"/>
<property name="idMerchant" type="int"/>
<property name="idUser" type="int"/>
<property name="status" type="string"/>
</transfer>

<transfer name="ImportProcessResponse">

</transfer>

<transfer name="ImportUploadResponse">
<property name="importUpload" type="ImportUpload"/>
<property name="isSuccessful" type="bool" strict="true"/>
<property name="message" type="string" strict="true"/>
</transfer>

</transfers>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0"?>
<transfers xmlns="spryker:transfer-01"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="spryker:transfer-01 http://static.spryker.com/transfer-01.xsd">

<transfer name="ProductImportGuiTableCriteria">
<property name="fkMerchant" type="int"/>
<property name="status" type="string"/>
<property name="page" type="int"/>
<property name="pageSize" type="int"/>
<property name="orderBy" type="string"/>
<property name="orderDirection" type="string"/>
<property name="filterStatus" type="string"/>
</transfer>

</transfers>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

use Pyz\Zed\FileUpload\Communication\Plugin\AclMerchantPortal\FileUploadAclEntityConfigurationExpanderPlugin;
use Pyz\Zed\FileUpload\Communication\Plugin\AclMerchantPortal\FileUploadMerchantAclEntityRuleExpanderPlugin;
use Pyz\Zed\FileUpload\Communication\Plugin\AclMerchantPortal\FileUploadMerchantPortalGuiMerchantAclRuleExpanderPlugin;
use Pyz\Zed\FileUploadMerchantPortalGui\Communication\Plugin\AclMerchantPortal\FileUploadMerchantPortalGuiMerchantAclRuleExpanderPlugin;
use Pyz\Zed\MerchantProductImport\Communication\Plugin\AclMerchantPortal\ImportUploadAclEntityConfigurationExpanderPlugin;
use Pyz\Zed\MerchantProductImport\Communication\Plugin\AclMerchantPortal\ImportUploadMerchantAclEntityRuleExpanderPlugin;
use Pyz\Zed\MerchantProductImportMerchantPortalGui\Communication\Plugin\AclMerchantPortal\MerchantProductImportMerchantAclRuleExpanderPlugin;
use Spryker\Zed\Acl\Communication\Plugin\AclMerchantPortal\AclEntityConfigurationExpanderPlugin;
use Spryker\Zed\AclEntity\Communication\Plugin\AclMerchantPortal\AclEntityAclEntityConfigurationExpanderPlugin;
use Spryker\Zed\AclMerchantPortal\AclMerchantPortalDependencyProvider as SprykerAclMerchantPortalDependencyProvider;
Expand Down Expand Up @@ -114,6 +117,7 @@ protected function getMerchantAclRuleExpanderPlugins(): array
new ProductOfferServicePointMerchantPortalGuiMerchantAclRuleExpanderPlugin(),
new MerchantAppMerchantPortalGuiMerchantAclRuleExpanderPlugin(),
new FileUploadMerchantPortalGuiMerchantAclRuleExpanderPlugin(),
new MerchantProductImportMerchantAclRuleExpanderPlugin(),
];
}

Expand Down Expand Up @@ -143,6 +147,8 @@ protected function getMerchantAclEntityRuleExpanderPlugins(): array
new DiscountMerchantAclEntityRuleExpanderPlugin(),
new DiscountPromotionMerchantAclEntityRuleExpanderPlugin(),
new SalesMerchantCommissionMerchantAclEntityRuleExpanderPlugin(),
new FileUploadMerchantAclEntityRuleExpanderPlugin(),
new ImportUploadMerchantAclEntityRuleExpanderPlugin(),
];
}

Expand All @@ -164,7 +170,6 @@ protected function getMerchantUserAclEntityRuleExpanderPlugins(): array
{
return [
new MerchantUserMerchantUserAclEntityRuleExpanderPlugin(),
new FileUploadMerchantAclEntityRuleExpanderPlugin(),
];
}

Expand Down Expand Up @@ -231,6 +236,7 @@ protected function getAclEntityConfigurationExpanderPlugins(): array
new MerchantAppAclEntityConfigurationExpanderPlugin(),
new SalesMerchantCommissionAclEntityConfigurationExpanderPlugin(),
new FileUploadAclEntityConfigurationExpanderPlugin(),
new ImportUploadAclEntityConfigurationExpanderPlugin(),
];
}
}
9 changes: 9 additions & 0 deletions src/Pyz/Zed/FileUpload/Business/FileUploadBusinessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function createFileUploadWriter(): FileUploadWriterInterface
$this->getEntityManager(),
$this->getMerchantUserFacade(),
$this->getAwsS3Service(),
$this->getFileUploadPostSavePlugins(),
);
}

Expand All @@ -77,4 +78,12 @@ private function getAwsS3Service(): AwsS3ServiceInterface
{
return $this->getProvidedDependency(FileUploadDependencyProvider::SERVICE_AWS_S3);
}

/**
* @return array<\Pyz\Zed\FileUpload\Dependency\Plugin\FileUploadPostSavePluginInterface>
*/
private function getFileUploadPostSavePlugins(): array
{
return $this->getProvidedDependency(FileUploadDependencyProvider::PLUGINS_FILE_UPLOAD_POST_SAVE);
}
}
35 changes: 28 additions & 7 deletions src/Pyz/Zed/FileUpload/Business/Writer/FileUploadWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Generated\Shared\Transfer\FileUploadTransfer;
use Pyz\Service\AwsS3\AwsS3ServiceInterface;
use Pyz\Service\AwsS3\Exception\S3BucketConfigurationNotFoundException;
use Pyz\Zed\FileUpload\Persistence\FileUploadEntityManagerInterface;
use Spryker\Zed\MerchantUser\Business\MerchantUserFacadeInterface;

Expand All @@ -22,14 +23,21 @@ class FileUploadWriter implements FileUploadWriterInterface

private AwsS3ServiceInterface $awsS3Service;

/**
* @return array<\Pyz\Zed\FileUpload\Dependency\Plugin\FileUploadPostSavePluginInterface>
*/
private array $fileUploadPostSavePlugins;

public function __construct(
FileUploadEntityManagerInterface $entityManager,
MerchantUserFacadeInterface $merchantUserFacade,
AwsS3ServiceInterface $awsS3Service,
array $fileUploadPostSavePlugins,
) {
$this->entityManager = $entityManager;
$this->merchantUserFacade = $merchantUserFacade;
$this->awsS3Service = $awsS3Service;
$this->fileUploadPostSavePlugins = $fileUploadPostSavePlugins;
}

public function createFileUpload(FileUploadTransfer $fileUploadTransfer): FileUploadTransfer
Expand All @@ -45,7 +53,9 @@ public function createFileUpload(FileUploadTransfer $fileUploadTransfer): FileUp
$this->setFileUploadS3Url($fileUploadTransfer);
$this->setFileUploadCdnUrl($fileUploadTransfer);

$this->entityManager->createFileUpload($fileUploadTransfer);
$fileUploadTransfer = $this->entityManager->createFileUpload($fileUploadTransfer);

$this->executePostSavePlugins($fileUploadTransfer);

return $fileUploadTransfer;
}
Expand All @@ -57,12 +67,16 @@ public function createFileUpload(FileUploadTransfer $fileUploadTransfer): FileUp
*/
private function setFileUploadCdnUrl(FileUploadTransfer $fileUploadTransfer): void
{
$cdnUrl = $this->awsS3Service->getCdnUrl(
$fileUploadTransfer->getFileName(),
$fileUploadTransfer->getObjectType(),
);

$fileUploadTransfer->setCdnUrl($cdnUrl);
try {
$cdnUrl = $this->awsS3Service->getCdnUrl(
$fileUploadTransfer->getFileName(),
$fileUploadTransfer->getObjectType(),
);

$fileUploadTransfer->setCdnUrl($cdnUrl);
} catch (S3BucketConfigurationNotFoundException) {
return;
}
}

/**
Expand Down Expand Up @@ -96,4 +110,11 @@ private function setFileUploadOwner(FileUploadTransfer $fileUploadTransfer): voi
->setFkMerchant($merchantUserTransfer->getIdMerchant())
->setFkUser($merchantUserTransfer->getIdUser());
}

private function executePostSavePlugins(FileUploadTransfer $fileUploadTransfer): void
{
foreach ($this->fileUploadPostSavePlugins as $fileUploadPostSavePlugin) {
$fileUploadPostSavePlugin->execute($fileUploadTransfer);
}
}
}
Loading

0 comments on commit eebc286

Please sign in to comment.