forked from Sylius/AdminOrderCreationPlugin
-
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.
Merge pull request Sylius#81 from bitbager/master
[Shop] Present the admin data in the store
- Loading branch information
Showing
78 changed files
with
1,354 additions
and
427 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* This file was created by the developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on [email protected]. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\CmsPlugin\Controller; | ||
|
||
use FOS\RestBundle\View\View; | ||
use Sylius\Bundle\ResourceBundle\Controller\ResourceController; | ||
use Sylius\Component\Resource\ResourceActions; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @author Mikołaj Król <[email protected]> | ||
*/ | ||
final class BlockController extends ResourceController | ||
{ | ||
/** | ||
* @param Request $request | ||
* | ||
* @return Response | ||
*/ | ||
public function renderBlockAction(Request $request): Response | ||
{ | ||
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request); | ||
|
||
$this->isGrantedOr403($configuration, ResourceActions::SHOW); | ||
|
||
$code = $request->get('code'); | ||
$blockResourceResolver = $this->get('bitbag.resolver.block_resource'); | ||
|
||
$block = $blockResourceResolver->findOrLog($code); | ||
|
||
if (null === $block) { | ||
return new Response(); | ||
} | ||
|
||
$this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $block); | ||
|
||
$view = View::create($block); | ||
$blockTemplateResolver = $this->get('bitbag.resolver.block_template'); | ||
$template = $blockTemplateResolver->resolveTemplate($block); | ||
|
||
if ($configuration->isHtmlRequest()) { | ||
$view | ||
->setTemplate($template) | ||
->setTemplateVar($this->metadata->getName()) | ||
->setData([ | ||
'configuration' => $configuration, | ||
'metadata' => $this->metadata, | ||
'resource' => $block, | ||
$this->metadata->getName() => $block, | ||
]) | ||
; | ||
} | ||
|
||
return $this->viewHandler->handle($configuration, $view); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
/** | ||
* @author Mikołaj Król <[email protected]> | ||
*/ | ||
interface ProductableInterface | ||
interface ProductsAwareInterface | ||
{ | ||
public function initializeProductsCollection(): void; | ||
|
||
|
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 |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
/** | ||
* @author Mikołaj Król <[email protected]> | ||
*/ | ||
trait ProductableTrait | ||
trait ProductsAwareTrait | ||
{ | ||
/** | ||
* @var Collection|ProductInterface[] | ||
|
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 |
---|---|---|
|
@@ -25,7 +25,7 @@ class Section implements SectionInterface | |
} | ||
|
||
/** | ||
* @var int | ||
* @var null|int | ||
*/ | ||
protected $id; | ||
|
||
|
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 |
---|---|---|
|
@@ -52,4 +52,4 @@ public function setName(?string $name): void | |
{ | ||
$this->name = $name; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -12,111 +12,43 @@ | |
|
||
namespace BitBag\CmsPlugin\Fixture; | ||
|
||
use BitBag\CmsPlugin\Entity\BlockInterface; | ||
use BitBag\CmsPlugin\Entity\BlockTranslationInterface; | ||
use BitBag\CmsPlugin\Entity\BlockImage; | ||
use BitBag\CmsPlugin\Factory\BlockFactoryInterface; | ||
use BitBag\CmsPlugin\Repository\BlockRepositoryInterface; | ||
use BitBag\CmsPlugin\Fixture\Factory\FixtureFactoryInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Sylius\Component\Core\Uploader\ImageUploaderInterface; | ||
use Sylius\Component\Resource\Factory\FactoryInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
/** | ||
* @author Mikołaj Król <[email protected]> | ||
*/ | ||
final class BlockFixture extends AbstractFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var BlockFactoryInterface | ||
* @var FixtureFactoryInterface | ||
*/ | ||
private $blockFactory; | ||
private $blockFixtureFactory; | ||
|
||
/** | ||
* @var FactoryInterface | ||
* @param FixtureFactoryInterface $blockFixtureFactory | ||
*/ | ||
private $blockTranslationFactory; | ||
|
||
/** | ||
* @var BlockRepositoryInterface | ||
*/ | ||
private $blockRepository; | ||
|
||
/** | ||
* @var ImageUploaderInterface | ||
*/ | ||
private $imageUploader; | ||
|
||
/** | ||
* @param BlockFactoryInterface $blockFactory | ||
* @param FactoryInterface $blockTranslationFactory | ||
* @param BlockRepositoryInterface $blockRepository | ||
* @param ImageUploaderInterface $imageUploader | ||
*/ | ||
public function __construct( | ||
BlockFactoryInterface $blockFactory, | ||
FactoryInterface $blockTranslationFactory, | ||
BlockRepositoryInterface $blockRepository, | ||
ImageUploaderInterface $imageUploader | ||
) | ||
public function __construct(FixtureFactoryInterface $blockFixtureFactory) | ||
{ | ||
$this->blockFactory = $blockFactory; | ||
$this->blockTranslationFactory = $blockTranslationFactory; | ||
$this->blockRepository = $blockRepository; | ||
$this->imageUploader = $imageUploader; | ||
$this->blockFixtureFactory = $blockFixtureFactory; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function load(array $options): void | ||
{ | ||
foreach ($options['blocks'] as $code => $fields) { | ||
|
||
if (null !== $this->blockRepository->findOneBy(['code' => $code])) { | ||
continue; | ||
} | ||
|
||
$type = $fields['type']; | ||
$block = $this->blockFactory->createWithType($type); | ||
|
||
$block->setCode($code); | ||
$block->setEnabled($fields['enabled']); | ||
|
||
foreach ($fields['translations'] as $localeCode => $translation) { | ||
/** @var BlockTranslationInterface $blockTranslation */ | ||
$blockTranslation = $this->blockTranslationFactory->createNew(); | ||
|
||
$blockTranslation->setLocale($localeCode); | ||
$blockTranslation->setName($translation['name']); | ||
$blockTranslation->setContent($translation['content']); | ||
|
||
if (BlockInterface::IMAGE_BLOCK_TYPE === $type) { | ||
$image = new BlockImage(); | ||
$path = $translation['image_path']; | ||
$uploadedImage = new UploadedFile($path, md5($path) . '.jpg'); | ||
|
||
$image->setFile($uploadedImage); | ||
$blockTranslation->setImage($image); | ||
|
||
$this->imageUploader->upload($image); | ||
} | ||
|
||
$block->addTranslation($blockTranslation); | ||
} | ||
|
||
$this->blockRepository->add($block); | ||
} | ||
$this->blockFixtureFactory->load($options['custom']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getName(): string | ||
{ | ||
return 'bitbag_cms_block'; | ||
return 'block'; | ||
} | ||
|
||
/** | ||
|
@@ -126,9 +58,11 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void | |
{ | ||
$optionsNode | ||
->children() | ||
->arrayNode('blocks') | ||
->arrayNode('custom') | ||
->prototype('array') | ||
->children() | ||
->booleanNode('remove_existing')->defaultTrue()->end() | ||
->booleanNode('last_four_products')->defaultFalse()->end() | ||
->scalarNode('type')->isRequired()->cannotBeEmpty()->end() | ||
->booleanNode('enabled')->defaultTrue()->end() | ||
->arrayNode('translations') | ||
|
Oops, something went wrong.