-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
312 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
use Generated\Shared\Transfer\ProductAbstractTransfer; | ||
use Spryker\Zed\Product\Business\ProductFacadeInterface; | ||
use SprykerCommunity\Zed\ProductGtinCraftor\Business\Model\DataRetriever\DataRetrieverInterface; | ||
use SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade\ProductGtinCraftorToProductFacadeBridgeInterface; | ||
|
||
class ProductCraftor implements ProductCraftorInterface | ||
{ | ||
|
@@ -29,7 +30,7 @@ class ProductCraftor implements ProductCraftorInterface | |
* @param DataRetrieverInterface $openAirRetriever | ||
* @param ProductFacadeInterface $productFacade | ||
*/ | ||
public function __construct(DataRetrieverInterface $upcRetriever, DataRetrieverInterface $openAirRetriever, ProductFacadeInterface $productFacade) | ||
public function __construct(DataRetrieverInterface $upcRetriever, DataRetrieverInterface $openAirRetriever, ProductGtinCraftorToProductFacadeBridgeInterface $productFacade) | ||
Check failure on line 33 in src/SprykerCommunity/Zed/ProductGtinCraftor/Business/Model/ProductCraftor/ProductCraftor.php GitHub Actions / build
|
||
{ | ||
$this->upcRetriever = $upcRetriever; | ||
$this->openAirRetriever = $openAirRetriever; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/SprykerCommunity/Zed/ProductGtinCraftor/Communication/Controller/IndexController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerCommunity\Zed\ProductGtinCraftor\Communication\Controller; | ||
|
||
use Generated\Shared\Transfer\ProductAbstractTransfer; | ||
use Spryker\Zed\Kernel\Communication\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Wel\Zed\Ingredient\Communication\Controller\ViewController; | ||
|
||
/** | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\Communication\ProductGtinCraftorCommunicationFactory getFactory() | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\Business\ProductGtinCraftorFacadeInterface getFacade() | ||
*/ | ||
class IndexController extends AbstractController | ||
{ | ||
/** | ||
* @param \Symfony\Component\HttpFoundation\Request $request | ||
* | ||
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse | ||
* @throws \Spryker\Zed\Product\Business\Exception\ProductAbstractExistsException | ||
*/ | ||
public function indexAction(Request $request): array|RedirectResponse | ||
{ | ||
$productGtinForm = $this->getFactory()->createProductGtinCraftorForm([])->handleRequest($request); | ||
|
||
if($productGtinForm->isSubmitted() && $productGtinForm->isValid()){ | ||
$productAbstract = new ProductAbstractTransfer(); | ||
$productAbstract->setGtin($productGtinForm->getData()['gtin']); | ||
$productAbstract->setSku($productGtinForm->getData()['sku']); | ||
$productAbstract=$this->getFacade()->expandProductAbstractWithGtinData($productAbstract); | ||
$productAbstract=$this->getFacade()->expandProductAbstractWithOpenAIData($productAbstract); | ||
$productAbstract=$this->getFacade()->expandProductAbsractWithLMIVData($productAbstract); | ||
$productAbstract->setIdTaxSet(1); | ||
$id=$this->getFactory()->getProductFacade()->createProductAbstract($productAbstract); | ||
|
||
return $this->redirectResponse(sprintf('/product-management/edit?id-product-abstract=%s', $id)); | ||
} | ||
|
||
return $this->viewResponse( | ||
[ | ||
'productGtinForm' => $productGtinForm->createView(), | ||
], | ||
); | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
src/SprykerCommunity/Zed/ProductGtinCraftor/Communication/Form/ProductGtinCraftorForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerCommunity\Zed\ProductGtinCraftor\Communication\Form; | ||
|
||
use Spryker\Zed\Kernel\Communication\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\TextType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
/** | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\Business\ProductGtinCraftorFacadeInterface getFacade() | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\Communication\ProductGtinCraftorCommunicationFactory getFactory() | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\ProductGtinCraftorConfig getConfig() | ||
*/ | ||
class ProductGtinCraftorForm extends AbstractType | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected const FIELD_GTIN = 'gtin'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const FIELD_SKU = 'sku'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected const FIELD_PRICE = 'price'; | ||
|
||
/** | ||
* @param \Symfony\Component\Form\FormBuilderInterface $builder | ||
* @param array $options | ||
* | ||
* @return void | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
$this->addProductGtinCraftorForm($builder, $options); | ||
} | ||
|
||
/** | ||
* @param \Symfony\Component\Form\FormBuilderInterface $builder | ||
* @param array $options | ||
* | ||
* @return $this | ||
*/ | ||
protected function addProductGtinCraftorForm(FormBuilderInterface $builder, array $options): static | ||
{ | ||
$builder->add( | ||
static::FIELD_GTIN, | ||
TextType::class, | ||
[ | ||
'label' => 'GTIN', | ||
'required' => true, | ||
], | ||
); | ||
|
||
$builder->add( | ||
static::FIELD_SKU, | ||
TextType::class, | ||
[ | ||
'label' => 'SKU', | ||
'required' => false, | ||
], | ||
); | ||
|
||
$builder->add( | ||
static::FIELD_PRICE, | ||
TextType::class, | ||
[ | ||
'label' => 'Price', | ||
'required' => true, | ||
], | ||
); | ||
|
||
return $this; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...Community/Zed/ProductGtinCraftor/Communication/ProductGtinCraftorCommunicationFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
/** | ||
* MIT License | ||
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. | ||
*/ | ||
|
||
namespace SprykerCommunity\Zed\ProductGtinCraftor\Communication; | ||
|
||
use Generated\Shared\Transfer\ProductAbstractTransfer; | ||
use Spryker\Zed\Kernel\Communication\AbstractCommunicationFactory; | ||
use SprykerCommunity\Zed\ProductGtinCraftor\Communication\Form\ProductGtinCraftorForm; | ||
use SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade\ProductGtinCraftorToProductFacadeBridgeInterface; | ||
use SprykerCommunity\Zed\ProductGtinCraftor\ProductGtinCraftorDependencyProvider; | ||
use Symfony\Component\Form\FormInterface; | ||
|
||
/** | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\Business\ProductGtinCraftorFacadeInterface getFacade() | ||
* @method \SprykerCommunity\Zed\ProductGtinCraftor\ProductGtinCraftorConfig getConfig() | ||
*/ | ||
class ProductGtinCraftorCommunicationFactory extends AbstractCommunicationFactory | ||
{ | ||
public function createProductGtinCraftorForm(array $data, array $options = []): FormInterface | ||
{ | ||
return $this->getFormFactory()->create(ProductGtinCraftorForm::class, $data, $options); | ||
} | ||
|
||
|
||
public function getProductFacade(): ProductGtinCraftorToProductFacadeBridgeInterface | ||
{ | ||
return $this->getProvidedDependency(ProductGtinCraftorDependencyProvider::FACADE_PRODUCT); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...nity/Zed/ProductGtinCraftor/Dependency/Facade/ProductGtinCraftorToProductFacadeBridge.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade; | ||
|
||
use Generated\Shared\Transfer\ProductAbstractTransfer; | ||
use Spryker\Zed\Product\Business\ProductFacadeInterface; | ||
|
||
class ProductGtinCraftorToProductFacadeBridge implements ProductGtinCraftorToProductFacadeBridgeInterface | ||
{ | ||
|
||
public function __construct(protected ProductFacadeInterface $productFacade){} | ||
|
||
/** | ||
* Specification: | ||
* - Saves abstract product attributes. | ||
* - Saves abstract product localized attributes. | ||
* - Saves abstract product meta data. | ||
* - Updates the URL of an active abstract product if it is changed. | ||
* - Triggers "before" and "after" CREATE plugins. | ||
* - Throws exception if an abstract product with the same SKU exists. | ||
* - Does not activate or touche created abstract product. | ||
* - Returns the ID of the newly created abstract product. | ||
* | ||
* @api | ||
* | ||
* @param \Generated\Shared\Transfer\ProductAbstractTransfer $productAbstractTransfer | ||
* | ||
* @throws \Spryker\Zed\Product\Business\Exception\ProductAbstractExistsException | ||
* | ||
* @return int | ||
*/ | ||
public function saveProductAbstract(ProductAbstractTransfer $productAbstractTransfer){ | ||
return $this->productFacade->saveProductAbstract($productAbstractTransfer); | ||
} | ||
/** | ||
* Specification: | ||
* - Adds abstract product attributes. | ||
* - Adds abstract product localized attributes. | ||
* - Adds abstract product meta data. | ||
* - Triggers "before" and "after" CREATE plugins. | ||
* - Throws exception if an abstract product with the same SKU exists. | ||
* - Returns the ID of the newly created abstract product. | ||
* - Does not activate or touche created abstract product. | ||
* - Executes `ProductAbstractPreCreatePluginInterface` stack of plugins. | ||
* | ||
* @api | ||
* | ||
* @param \Generated\Shared\Transfer\ProductAbstractTransfer $productAbstractTransfer | ||
* | ||
* @throws \Spryker\Zed\Product\Business\Exception\ProductAbstractExistsException | ||
* | ||
* @return int | ||
*/ | ||
public function createProductAbstract(ProductAbstractTransfer $productAbstractTransfer){ | ||
return $this->productFacade->createProductAbstract($productAbstractTransfer); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...ProductGtinCraftor/Dependency/Facade/ProductGtinCraftorToProductFacadeBridgeInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade; | ||
|
||
use Generated\Shared\Transfer\ProductAbstractTransfer; | ||
|
||
interface ProductGtinCraftorToProductFacadeBridgeInterface | ||
{ | ||
/** | ||
* Specification: | ||
* - Saves abstract product attributes. | ||
* - Saves abstract product localized attributes. | ||
* - Saves abstract product meta data. | ||
* - Updates the URL of an active abstract product if it is changed. | ||
* - Triggers "before" and "after" CREATE plugins. | ||
* - Throws exception if an abstract product with the same SKU exists. | ||
* - Does not activate or touche created abstract product. | ||
* - Returns the ID of the newly created abstract product. | ||
* | ||
* @api | ||
* | ||
* @param \Generated\Shared\Transfer\ProductAbstractTransfer $productAbstractTransfer | ||
* | ||
* @throws \Spryker\Zed\Product\Business\Exception\ProductAbstractExistsException | ||
* | ||
* @return int | ||
*/ | ||
public function saveProductAbstract(ProductAbstractTransfer $productAbstractTransfer); | ||
|
||
/** | ||
* Specification: | ||
* - Adds abstract product attributes. | ||
* - Adds abstract product localized attributes. | ||
* - Adds abstract product meta data. | ||
* - Triggers "before" and "after" CREATE plugins. | ||
* - Throws exception if an abstract product with the same SKU exists. | ||
* - Returns the ID of the newly created abstract product. | ||
* - Does not activate or touche created abstract product. | ||
* - Executes `ProductAbstractPreCreatePluginInterface` stack of plugins. | ||
* | ||
* @api | ||
* | ||
* @param \Generated\Shared\Transfer\ProductAbstractTransfer $productAbstractTransfer | ||
* | ||
* @throws \Spryker\Zed\Product\Business\Exception\ProductAbstractExistsException | ||
* | ||
* @return int | ||
*/ | ||
public function createProductAbstract(ProductAbstractTransfer $productAbstractTransfer); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/SprykerCommunity/Zed/ProductGtinCraftor/Presentation/Index/index.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends '@Gui/Layout/layout.twig' %} | ||
|
||
{% set widget_title = 'Product GTIN' | trans %} | ||
{% block section_title %}{{ widget_title }}{% endblock %} | ||
|
||
{% block content %} | ||
{{ form_start(productGtinForm) }} | ||
{{ form_widget(productGtinForm) }} | ||
<input type="submit" class="btn btn-primary safe-submit" value="{{ 'Save' | trans }}" /> | ||
{{ form_end(productGtinForm) }} | ||
{% endblock %} |
Oops, something went wrong.