-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from lruozzi9/enqueue-product
Enqueue product
- Loading branch information
Showing
14 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,82 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Webgriffe\SyliusAkeneoPlugin\Controller; | ||
|
||
use Sylius\Component\Product\Model\ProductInterface; | ||
use Sylius\Component\Product\Repository\ProductRepositoryInterface; | ||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
use Symfony\Contracts\Translation\TranslatorInterface; | ||
use Webgriffe\SyliusAkeneoPlugin\Entity\QueueItem; | ||
use Webgriffe\SyliusAkeneoPlugin\Repository\QueueItemRepositoryInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class ProductEnqueueController extends AbstractController | ||
{ | ||
/** @var QueueItemRepositoryInterface */ | ||
private $queueItemRepository; | ||
|
||
/** @var UrlGeneratorInterface */ | ||
private $urlGenerator; | ||
|
||
/** @var ProductRepositoryInterface */ | ||
private $productRepository; | ||
|
||
/** | ||
* ProductEnqueueController constructor. | ||
*/ | ||
public function __construct(QueueItemRepositoryInterface $queueItemRepository, ProductRepositoryInterface $productRepository, UrlGeneratorInterface $urlGenerator) | ||
{ | ||
$this->queueItemRepository = $queueItemRepository; | ||
$this->urlGenerator = $urlGenerator; | ||
$this->productRepository = $productRepository; | ||
} | ||
|
||
public function enqueueAction(int $productId): Response | ||
{ | ||
/** @var TranslatorInterface $translator */ | ||
$translator = $this->get('translator'); | ||
/** @var ProductInterface|null $product */ | ||
$product = $this->productRepository->find($productId); | ||
if ($product === null) { | ||
throw new NotFoundHttpException('Product not found'); | ||
} | ||
|
||
/** @var array $productEnqueued */ | ||
$productEnqueued = $this->queueItemRepository->findBy([ | ||
'akeneoIdentifier' => $product->getCode(), | ||
'akeneoEntity' => 'Product', | ||
'importedAt' => null, | ||
]); | ||
if (count($productEnqueued) > 0) { | ||
$this->addFlash( | ||
'error', | ||
$translator->trans('webgriffe_sylius_akeneo.ui.product_already_enqueued') | ||
); | ||
|
||
return $this->redirectToRoute('sylius_admin_product_index'); | ||
} | ||
|
||
/** @var ?string $productCode */ | ||
$productCode = $product->getCode(); | ||
|
||
Assert::notNull($productCode); | ||
|
||
$queueItem = new QueueItem(); | ||
$queueItem->setAkeneoEntity('Product'); | ||
$queueItem->setAkeneoIdentifier($productCode); | ||
$queueItem->setCreatedAt(new \DateTime()); | ||
$this->queueItemRepository->add($queueItem); | ||
|
||
$this->addFlash( | ||
'success', | ||
$translator->trans('webgriffe_sylius_akeneo.ui.enqueued_success') | ||
); | ||
|
||
return $this->redirectToRoute('sylius_admin_product_index'); | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{% import '@SyliusUi/Macro/buttons.html.twig' as buttons %} | ||
|
||
{% set path = options.link.url|default(path(options.link.route, options.link.parameters)) %} | ||
|
||
{{ buttons.default(path, action.label, null, options.icon, options.color) }} |
42 changes: 42 additions & 0 deletions
42
tests/Application/templates/bundles/SyliusAdminBundle/Product/_showInShopButton.html.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,42 @@ | ||
{% set enabledChannels = product.channels|filter(channel => channel.enabled == true) %} | ||
|
||
{% if sylius_bundle_loaded_checker('SyliusShopBundle') %} | ||
{% if not product.enabled or enabledChannels|length < 1 %} | ||
<a class="ui labeled icon button disabled" href="#"> | ||
<i class="angle right icon"></i> | ||
{{ 'sylius.ui.show_product_in_shop_page'|trans }} | ||
</a> | ||
{% elseif enabledChannels|length > 1 %} | ||
<div class="ui floating dropdown labeled icon button"> | ||
<i class="share alternate icon"></i> | ||
<span class="text"> | ||
{{ 'sylius.ui.show_product_in_shop_page'|trans }} | ||
</span> | ||
<div class="menu"> | ||
<div class="scrolling menu"> | ||
{% for channel in enabledChannels %} | ||
{% set url = channel.hostname is not null ? 'http://' ~ channel.hostname ~ path('sylius_shop_product_show', {'slug': product.slug, '_locale': channel.defaultLocale.code}) : url('sylius_shop_product_show', {'slug': product.slug, '_locale': channel.defaultLocale.code}) %} | ||
<a href="{{ url|raw }}" class="item" target="_blank"> | ||
<i class="angle right icon"></i> | ||
{{ 'sylius.ui.show_in'|trans }} | ||
{{ channel.name }} ({{ channel.code }}) | ||
</a> | ||
{% endfor %} | ||
</div> | ||
</div> | ||
</div> | ||
{% else %} | ||
{% for channel in enabledChannels %} | ||
{% set url = channel.hostname is not null ? 'http://' ~ channel.hostname ~ path('sylius_shop_product_show', {'slug': product.slug, '_locale': channel.defaultLocale.code}) : url('sylius_shop_product_show', {'slug': product.slug, '_locale': channel.defaultLocale.code}) %} | ||
<a class="ui labeled icon button" href="{{ url|raw }}" target="_blank"> | ||
<i class="angle right icon"></i> | ||
{{ 'sylius.ui.show_product_in_shop_page'|trans }} | ||
</a> | ||
{% endfor %} | ||
{% endif %} | ||
{% endif %} | ||
|
||
<a class="ui labeled icon button violet" href="{{ path('webgriffe_sylius_akeneo_product_enqueue', {'productId': product.id }) }}" > | ||
<i class="icon cloud download"></i> | ||
{{ 'webgriffe_sylius_akeneo.ui.enqueue'|trans }} | ||
</a> |
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,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Webgriffe\SyliusAkeneoPlugin\Behat\Context\Ui\Admin; | ||
|
||
use Behat\Behat\Context\Context; | ||
use Behat\Mink\Element\NodeElement; | ||
use Sylius\Behat\NotificationType; | ||
use Sylius\Behat\Page\Admin\Product\IndexPageInterface; | ||
use Sylius\Behat\Service\Helper\JavaScriptTestHelperInterface; | ||
use Sylius\Behat\Service\NotificationCheckerInterface; | ||
|
||
final class ManagingProductsContext implements Context | ||
{ | ||
private const SCHEDULE_AKENEO_PIM_IMPORT = 'Schedule Akeneo PIM import'; | ||
|
||
/** @var IndexPageInterface */ | ||
private $indexPage; | ||
|
||
/** @var JavaScriptTestHelperInterface */ | ||
private $testHelper; | ||
|
||
/** @var NotificationCheckerInterface */ | ||
private $notificationChecker; | ||
|
||
/** | ||
* ProductItems constructor. | ||
*/ | ||
public function __construct(IndexPageInterface $indexPage, JavaScriptTestHelperInterface $testHelper, NotificationCheckerInterface $notificationChecker) | ||
{ | ||
$this->indexPage = $indexPage; | ||
$this->testHelper = $testHelper; | ||
$this->notificationChecker = $notificationChecker; | ||
} | ||
|
||
/** | ||
* @When /^I schedule an Akeneo PIM import for the "([^"]*)" product$/ | ||
*/ | ||
public function scheduleAnAkeneoPimImportForTheProduct($code) | ||
{ | ||
/** @var NodeElement $actionsNodeProduct */ | ||
$actionsNodeProduct = $this->indexPage->getActionsForResource(['code' => $code]); | ||
|
||
$actionsNodeProduct->clickLink(self::SCHEDULE_AKENEO_PIM_IMPORT); | ||
} | ||
|
||
/** | ||
* @Then I should be notified that it has been successfully enqueued | ||
*/ | ||
public function iShouldBeNotifiedThatItHasBeenSuccessfullyEnqueued() | ||
{ | ||
$this->testHelper->waitUntilNotificationPopups( | ||
$this->notificationChecker, NotificationType::success(), 'Akeneo PIM product import has been successfully scheduled' | ||
); | ||
} | ||
|
||
/** | ||
* @Given /^I should be notified that it has been already enqueued$/ | ||
*/ | ||
public function iShouldBeNotifiedThatItHasBeenAlreadyEnqueued() | ||
{ | ||
$this->testHelper->waitUntilNotificationPopups( | ||
$this->notificationChecker, NotificationType::success(), 'Akeneo PIM import for this product has been already scheduled before' | ||
); | ||
} | ||
} |
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