Skip to content

Commit edbd966

Browse files
committed
init
0 parents  commit edbd966

37 files changed

+908
-0
lines changed

.gitignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/bin/*
2+
!/bin/.gitkeep
3+
4+
/vendor/
5+
/node_modules/
6+
/composer.lock
7+
8+
/etc/build/*
9+
!/etc/build/.gitkeep
10+
11+
/tests/Application/yarn.lock

.travis.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
language: php
2+
3+
dist: trusty
4+
5+
sudo: false
6+
7+
php:
8+
- 7.1
9+
- 7.2
10+
11+
cache:
12+
yarn: true
13+
directories:
14+
- ~/.composer/cache/files
15+
- $SYLIUS_CACHE_DIR
16+
17+
env:
18+
global:
19+
- SYLIUS_CACHE_DIR=$HOME/.sylius-cache
20+
- SYLIUS_BUILD_DIR=etc/build
21+
22+
before_install:
23+
- phpenv config-rm xdebug.ini
24+
- echo "memory_limit=4096M" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
25+
- mkdir -p "${SYLIUS_CACHE_DIR}"
26+
27+
install:
28+
- composer install --no-interaction --prefer-dist
29+
- (cd tests/Application && yarn install)
30+
31+
before_script:
32+
- (cd tests/Application && bin/console doctrine:database:create --env=test -vvv)
33+
- (cd tests/Application && bin/console doctrine:schema:create --env=test -vvv)
34+
- (cd tests/Application && bin/console assets:install web --env=test -vvv)
35+
- (cd tests/Application && yarn run gulp)
36+
37+
# Configure display
38+
- /sbin/start-stop-daemon --start --quiet --pidfile /tmp/xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 1680x1050x16
39+
- export DISPLAY=:99
40+
41+
# Download and configure ChromeDriver
42+
- |
43+
if [ ! -f $SYLIUS_CACHE_DIR/chromedriver ] || [ "$($SYLIUS_CACHE_DIR/chromedriver --version | grep -c 2.34)" = "0" ]; then
44+
curl http://chromedriver.storage.googleapis.com/2.34/chromedriver_linux64.zip > chromedriver.zip
45+
unzip chromedriver.zip
46+
chmod +x chromedriver
47+
mv chromedriver $SYLIUS_CACHE_DIR
48+
fi
49+
50+
# Run ChromeDriver
51+
- $SYLIUS_CACHE_DIR/chromedriver > /dev/null 2>&1 &
52+
53+
# Download and configure Selenium
54+
- |
55+
if [ ! -f $SYLIUS_CACHE_DIR/selenium.jar ] || [ "$(java -jar $SYLIUS_CACHE_DIR/selenium.jar --version | grep -c 3.4.0)" = "0" ]; then
56+
curl http://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar > selenium.jar
57+
mv selenium.jar $SYLIUS_CACHE_DIR
58+
fi
59+
60+
# Run Selenium
61+
- java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &
62+
63+
# Run webserver
64+
- (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web --env=test --quiet > /dev/null 2>&1 &)
65+
66+
script:
67+
- composer validate --strict
68+
- bin/phpstan.phar analyse -c phpstan.neon -l max src/
69+
70+
- bin/phpunit
71+
- bin/phpspec run
72+
- bin/behat --strict -vvv --no-interaction || bin/behat --strict -vvv --no-interaction --rerun
73+
74+
after_failure:
75+
- vendor/lakion/mink-debug-extension/travis/tools/upload-textfiles "${SYLIUS_BUILD_DIR}/*.log"

README.md

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<p align="center">
2+
<a href="http://sylius.org" target="_blank">
3+
<img src="http://demo.sylius.org/assets/shop/img/logo.png" />
4+
</a>
5+
</p>
6+
<h1 align="center">Plugin Skeleton</h1>
7+
<p align="center">
8+
<a href="https://packagist.org/packages/sylius/plugin-skeleton" title="License">
9+
<img src="https://img.shields.io/packagist/l/sylius/plugin-skeleton.svg" />
10+
</a>
11+
<a href="https://packagist.org/packages/sylius/plugin-skeleton" title="Version">
12+
<img src="https://img.shields.io/packagist/v/sylius/plugin-skeleton.svg" />
13+
</a>
14+
<a href="http://travis-ci.org/Sylius/PluginSkeleton" title="Build status">
15+
<img src="https://img.shields.io/travis/Sylius/PluginSkeleton/master.svg" />
16+
</a>
17+
<a href="https://scrutinizer-ci.com/g/Sylius/PluginSkeleton/" title="Scrutinizer">
18+
<img src="https://img.shields.io/scrutinizer/g/Sylius/PluginSkeleton.svg" />
19+
</a>
20+
</p>
21+
22+
## Installation
23+
24+
1. Run `composer create-project sylius/plugin-skeleton ProjectName`.
25+
26+
2. From the plugin skeleton root directory, run the following commands:
27+
28+
```bash
29+
$ (cd tests/Application && yarn install)
30+
$ (cd tests/Application && yarn run gulp)
31+
$ (cd tests/Application && bin/console assets:install web -e test)
32+
33+
$ (cd tests/Application && bin/console doctrine:database:create -e test)
34+
$ (cd tests/Application && bin/console doctrine:schema:create -e test)
35+
```
36+
37+
## Usage
38+
39+
### Running plugin tests
40+
41+
- PHPUnit
42+
43+
```bash
44+
$ bin/phpunit
45+
```
46+
47+
- PHPSpec
48+
49+
```bash
50+
$ bin/phpspec run
51+
```
52+
53+
- Behat (non-JS scenarios)
54+
55+
```bash
56+
$ bin/behat --tags="~@javascript"
57+
```
58+
59+
- Behat (JS scenarios)
60+
61+
1. Download [Chromedriver](https://sites.google.com/a/chromium.org/chromedriver/)
62+
63+
2. Run Selenium server with previously downloaded Chromedriver:
64+
65+
```bash
66+
$ bin/selenium-server-standalone -Dwebdriver.chrome.driver=chromedriver
67+
```
68+
3. Run test application's webserver on `localhost:8080`:
69+
70+
```bash
71+
$ (cd tests/Application && bin/console server:run 127.0.0.1:8080 -d web -e test)
72+
```
73+
74+
4. Run Behat:
75+
76+
```bash
77+
$ bin/behat --tags="@javascript"
78+
```
79+
80+
### Opening Sylius with your plugin
81+
82+
- Using `test` environment:
83+
84+
```bash
85+
$ (cd tests/Application && bin/console sylius:fixtures:load -e test)
86+
$ (cd tests/Application && bin/console server:run -d web -e test)
87+
```
88+
89+
- Using `dev` environment:
90+
91+
```bash
92+
$ (cd tests/Application && bin/console sylius:fixtures:load -e dev)
93+
$ (cd tests/Application && bin/console server:run -d web -e dev)
94+
```

behat.yml.dist

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
imports:
2+
- vendor/sylius/sylius/behat.yml.dist
3+
- tests/Behat/Resources/suites.yml
4+
5+
default:
6+
extensions:
7+
FriendsOfBehat\ContextServiceExtension:
8+
imports:
9+
- vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml
10+
- tests/Behat/Resources/services.xml
11+
12+
FriendsOfBehat\SymfonyExtension:
13+
kernel:
14+
class: AppKernel
15+
path: tests/Application/app/AppKernel.php
16+
bootstrap: vendor/autoload.php
17+
18+
Lakion\Behat\MinkDebugExtension:
19+
directory: etc/build
20+
clean_start: false
21+
screenshot: true

bin/.gitkeep

Whitespace-only changes.

composer.json

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"name": "sylius/plugin-skeleton",
3+
"type": "sylius-plugin",
4+
"description": "Acme example plugin for Sylius.",
5+
"license": "MIT",
6+
"require": {
7+
"php": "^7.1",
8+
9+
"sylius/sylius": "^1.2@dev",
10+
"friendsofsymfony/elastica-bundle": "^5.0"
11+
},
12+
"require-dev": {
13+
"behat/behat": "^3.3",
14+
"behat/mink": "^1.7",
15+
"behat/mink-browserkit-driver": "^1.3",
16+
"behat/mink-extension": "^2.2",
17+
"behat/mink-selenium2-driver": "^1.3",
18+
"friends-of-behat/context-service-extension": "^1.0",
19+
"friends-of-behat/cross-container-extension": "^1.0",
20+
"friends-of-behat/service-container-extension": "^1.0",
21+
"friends-of-behat/symfony-extension": "^1.0",
22+
"friends-of-behat/variadic-extension": "^1.0",
23+
"lakion/mink-debug-extension": "^1.2.3",
24+
"phpspec/phpspec": "^3.2",
25+
"phpstan/phpstan-shim": "^0.9.2",
26+
"phpunit/phpunit": "^5.6",
27+
"se/selenium-server-standalone": "^2.52",
28+
"sylius-labs/coding-standard": "^1.0",
29+
"symplify/easy-coding-standard": "^2.4"
30+
},
31+
"prefer-stable": true,
32+
"autoload": {
33+
"psr-4": {
34+
"BitBag\\SyliusElasticsearchPlugin\\": "src/",
35+
"Tests\\BitBag\\SyliusElasticsearchPlugin\\": "tests/"
36+
}
37+
},
38+
"autoload-dev": {
39+
"classmap": ["tests/Application/app/AppKernel.php"]
40+
},
41+
"extra": {
42+
"branch-alias": {
43+
"dev-master": "1.1-dev"
44+
}
45+
},
46+
"config": {
47+
"bin-dir": "bin"
48+
}
49+
}

easy-coding-standard.neon

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
includes:
2+
- vendor/sylius-labs/coding-standard/easy-coding-standard.neon

etc/build/.gitkeep

Whitespace-only changes.

node_modules

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/Application/node_modules

phpspec.yml.dist

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
suites:
2+
main:
3+
namespace: BitBag\SyliusElasticsearchPlugin
4+
psr4_prefix: BitBag\SyliusElasticsearchPlugin

phpstan.neon

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
parameters:
2+
excludes_analyse:
3+
# Makes PHPStan crash
4+
- 'src/DependencyInjection/Configuration.php'
5+
6+
# Test dependencies
7+
- 'tests/Application/app/**.php'
8+
- 'tests/Application/src/**.php'
9+
10+
ignoreErrors:
11+
- '/Parameter #1 $configuration of method Symfony\Component\DependencyInjection\Extension\Extension::processConfiguration() expects Symfony\Component\Config\Definition\ConfigurationInterface, Symfony\Component\Config\Definition\ConfigurationInterface|null given./'

phpunit.xml.dist

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/5.6/phpunit.xsd"
5+
backupGlobals="false"
6+
colors="true"
7+
bootstrap="vendor/autoload.php">
8+
<testsuites>
9+
<testsuite name="BitBagSyliusElasticSearchPlugin Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
13+
14+
<php>
15+
<server name="KERNEL_CLASS_PATH" value="/tests/Application/AppKernel.php" />
16+
<server name="IS_DOCTRINE_ORM_SUPPORTED" value="true" />
17+
</php>
18+
</phpunit>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace BitBag\SyliusElasticsearchPlugin;
6+
7+
use Sylius\Bundle\CoreBundle\Application\SyliusPluginTrait;
8+
use Symfony\Component\HttpKernel\Bundle\Bundle;
9+
10+
final class BitBagSyliusElasticSearchPlugin extends Bundle
11+
{
12+
use SyliusPluginTrait;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
/*
4+
* This file has been created by developers from BitBag.
5+
* Feel free to contact us once you face any issues or want to start
6+
* another great project.
7+
* You can find more information about us on https://bitbag.shop and write us
8+
* an email on mikolaj.krol@bitbag.pl.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
14+
15+
use Elastica\Document;
16+
use FOS\ElasticaBundle\Event\TransformEvent;
17+
use Sylius\Component\Core\Model\ProductInterface;
18+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
19+
20+
final class ProductOptionsPropertyListener implements EventSubscriberInterface
21+
{
22+
/**
23+
* @param TransformEvent $event
24+
*/
25+
public function addProductOptionProperty(TransformEvent $event): void
26+
{
27+
/** @var ProductInterface $product */
28+
$product = $event->getObject();
29+
$document = $event->getDocument();
30+
31+
$this->resolveProductOptions($product, $document);
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*/
37+
public static function getSubscribedEvents(): array
38+
{
39+
return [
40+
TransformEvent::POST_TRANSFORM => 'addProductOptionProperty',
41+
];
42+
}
43+
44+
/**
45+
* @param ProductInterface $product
46+
* @param Document $document
47+
*/
48+
private function resolveProductOptions(ProductInterface $product, Document $document): void
49+
{
50+
foreach ($product->getVariants() as $productVariant) {
51+
foreach ($productVariant->getOptionValues() as $productOptionValue) {
52+
$optionCode = $productOptionValue->getOption()->getCode();
53+
$index = 'option_' . $optionCode;
54+
55+
if (!$document->has($index)) {
56+
$document->set($index, []);
57+
}
58+
59+
$reference = $document->get($index);
60+
$reference[] = $productOptionValue->getValue();
61+
62+
$document->set($index, $reference);
63+
}
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)