Skip to content

Commit

Permalink
added gui
Browse files Browse the repository at this point in the history
  • Loading branch information
a4blue committed Sep 13, 2023
1 parent 3da7f81 commit 47493c2
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
<transfer name="ProductAbstract">
<property name="localizedAttributes" type="LocalizedAttributes[]" singular="localizedAttributes"/>

<property name="idProductAbstract" type="int"/>

<property name="gtin" type="string"/>
<property name="sku" type="string"/>
<property name="idTaxSet" type="int"/>

<property name="upcBrand" type="string"/>
<property name="upcManufacturer" type="string"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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

View workflow job for this annotation

GitHub Actions / build

PHPDoc tag @param for parameter $productFacade with type Spryker\Zed\Product\Business\ProductFacadeInterface is not subtype of native type SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade\ProductGtinCraftorToProductFacadeBridgeInterface.
{
$this->upcRetriever = $upcRetriever;
$this->openAirRetriever = $openAirRetriever;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Client\ProductGtinCraftorToUpcDatabaseClientInterface;
use SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade\ProductGtinCraftorToLocaleFacadeInterface;
use SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade\ProductGtinCraftorToOpenAiFacadeInterface;
use SprykerCommunity\Zed\ProductGtinCraftor\Dependency\Facade\ProductGtinCraftorToProductFacadeBridgeInterface;
use SprykerCommunity\Zed\ProductGtinCraftor\ProductGtinCraftorDependencyProvider;

/**
Expand Down Expand Up @@ -64,7 +65,7 @@ protected function getLocaleFacade(): ProductGtinCraftorToLocaleFacadeInterface
return $this->getProvidedDependency(ProductGtinCraftorDependencyProvider::FACADE_LOCALE);
}

protected function getProductFacade(): ProductFacadeInterface
public function getProductFacade(): ProductGtinCraftorToProductFacadeBridgeInterface
{
return $this->getProvidedDependency(ProductGtinCraftorDependencyProvider::FACADE_PRODUCT);
}
Expand Down
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(),
],
);
}
}
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;
}
}
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);
}
}
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);
}
}
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);
}
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 %}
Loading

0 comments on commit 47493c2

Please sign in to comment.