Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2a34ac8
chore(codebase): [dir] move to new file structure
maxperei May 7, 2025
4d6d56e
feat(codebase): [upgrade] sylius v2.x compatibility
maxperei May 15, 2025
f9cc7d0
chore(ci): [actions] bump to match latest versions
maxperei May 15, 2025
0bc04d5
chore(lint): [grumphp] quality tools
maxperei May 15, 2025
717cbff
fix(ci): [setup] update paths relative to install folder
maxperei Jun 10, 2025
5480582
fix(ci): [deprecation] apply latest change according to doctrine/orm
maxperei Jun 10, 2025
8d71616
fix(tests): [env] unused variables
maxperei Jun 10, 2025
a3bfb26
fix(tests): [kernel] rm useless method
maxperei Jun 10, 2025
8e66d13
fix(tests): [attributes] empty array translation collection due to mi…
maxperei Jun 12, 2025
c0a2ff9
chore(deprecation): [entity] get rid of admin api configuration
maxperei Jun 13, 2025
b7e2b91
chore(entity): [apip] use proper attribute for api resource metadata …
maxperei Jun 13, 2025
1c21f66
chore(entity): [orm] get rid of annotations
maxperei Jun 13, 2025
655fc12
chore(config): [service] remove unneeded migration
maxperei Jun 13, 2025
62c2855
chore(config): [route] use absolute plugin path
maxperei Jun 13, 2025
b178dbe
chore(credit): [import] add author and link to the process manager
maxperei Jun 13, 2025
768c72f
chore(tests): [abstract] remove unused kernel test case
maxperei Jun 13, 2025
8e8ae37
chore(form): [validation] create validation group for taxon attribute…
maxperei Jun 13, 2025
64ce3d8
fix(twig): [hook] missing fallback url on cancel template
maxperei Jun 16, 2025
8ddf902
chore(ci): [actions] run on sylius 2.1
maxperei Jun 16, 2025
e90fa66
chore(admin): [templates] remove unused
maxperei Jun 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- 8.3
symfony:
- '6.4.*'
- '7.2.*'
env:
APP_ENV: test
steps:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/sylius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
- 8.2
- 8.3
sylius:
- 1.12.0
- 1.13.0
- 1.14.0
- 2.0.0
- 2.1.0
symfony:
- 6.4
- 7.2
node:
- 16.x
- 20.x
env:
APP_ENV: test
package-name: synolia/sylius-akeneo-plugin
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/tests/Application/
/install/Application/*.local
/install/app-*

/behat.yml
/phpspec.yml
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ CONSOLE=cd ${TEST_DIRECTORY} && php bin/console -e test
COMPOSER=cd ${TEST_DIRECTORY} && composer
YARN=cd ${TEST_DIRECTORY} && yarn

SYLIUS_VERSION=1.14.0
SYMFONY_VERSION=6.4
SYLIUS_VERSION=2.0
SYMFONY_VERSION=7.2
PHP_VERSION=8.2
PLUGIN_NAME=synolia/sylius-akeneo-plugin

Expand Down
18 changes: 3 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
| | Version |
|:-----------|:--------|
| PHP | ^8.2 |
| Sylius | ^1.12 |
| Sylius | ^2.0 |
| Akeneo PIM | >=v6.0 |


Expand All @@ -56,14 +56,14 @@

```yaml
imports:
- { resource: "@SynoliaSyliusAkeneoPlugin/Resources/config/config.yaml" }
- { resource: "@SynoliaSyliusAkeneoPlugin/config/config.yaml" }
```

4. Import routing in your `config/routes.yaml` file:

```yaml
synolia_akeneo:
resource: "@SynoliaSyliusAkeneoPlugin/Resources/config/routes.yaml"
resource: "@SynoliaSyliusAkeneoPlugin/config/routes.yaml"
prefix: '/%sylius_admin.path_name%'
```

Expand All @@ -82,10 +82,6 @@
use Sylius\Component\Product\Model\ProductTranslationInterface;
use Synolia\SyliusAkeneoPlugin\Entity\ProductAssetTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_product")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct
Expand Down Expand Up @@ -119,10 +115,6 @@
use Sylius\Component\Product\Model\ProductVariantTranslationInterface;
use Synolia\SyliusAkeneoPlugin\Entity\ProductVariantAssetTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_product_variant")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product_variant')]
class ProductVariant extends BaseProductVariant
Expand Down Expand Up @@ -158,10 +150,6 @@
use Synolia\SyliusAkeneoPlugin\Component\TaxonAttribute\Model\TaxonAttributeSubjectInterface;
use Synolia\SyliusAkeneoPlugin\Entity\TaxonAttributesTrait;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_taxon")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_taxon')]
class Taxon extends BaseTaxon implements TaxonAttributeSubjectInterface
Expand Down
86 changes: 86 additions & 0 deletions assets/controllers/form_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Controller } from '@hotwired/stimulus';
import $ from 'jquery';
import '../legacy/js/sylius-form-collection.js';

/* stimulusFetch: 'lazy' */
export default class extends Controller {
static values = {
std: String,
adv: String,
};
static targets = ['switch'];
initialize() {
this.options = {
locale: {
trigger: "#product_filter_rule_simple_completeness_type",
selector: "#product_filter_rule_simple_locales",
values: [
"GREATER THAN ON ALL LOCALES",
"GREATER OR EQUALS THAN ON ALL LOCALES",
"LOWER THAN ON ALL LOCALES",
"LOWER OR EQUALS THAN ON ALL LOCALES",
Comment thread
maxperei marked this conversation as resolved.
],
},
before: {
trigger: "#product_filter_rule_simple_updated_mode",
selector: "#product_filter_rule_simple_updated_before",
values: ["BETWEEN", "<"],
},
after: {
trigger: "#product_filter_rule_simple_updated_mode",
selector: "#product_filter_rule_simple_updated_after",
values: ["BETWEEN", ">"],
},
since: {
trigger: "#product_filter_rule_simple_updated_mode",
selector: "#product_filter_rule_simple_updated",
values: ["SINCE LAST N DAYS"],
},
}
}
connect() {
this.toggleFields();
$('[data-form-type="collection"]').CollectionForm();
if (!this.hasSwitchTarget) {
return;
}
if (this.switchTarget.checked || this.switchTarget.querySelector('input:checked')) {
this.switchTarget.dispatchEvent(new CustomEvent('input'));
}
}
toggleForms(e) {
if (this.hasStdValue && this.hasAdvValue) {
$(e.currentTarget).is(':checked')
? $('button[type=submit]').attr('form', this.advValue)
: $('button[type=submit]').attr('form', this.stdValue);
}
$(".form-switch > label").toggleClass("opacity-50");
$(".togglable").toggle();
}
toggleFields() {
const toHide = [
this.options.locale.selector,
this.options.before.selector,
this.options.after.selector,
this.options.since.selector,
];
for (let k in this.options) {
if (this.options[k].values.includes($(this.options[k].trigger).val())) {
let index = toHide.indexOf(this.options[k].selector);
if (index !== -1) {
toHide.splice(index, 1);
}
}
if ($(this.options[k].trigger).length) {
$(this.options[k].trigger).on("change", (e) => {
this.options[k].values.includes($(e.currentTarget).val())
? $(this.options[k].selector).parent(".field").removeClass("d-none")
: $(this.options[k].selector).parent(".field").addClass("d-none");
});
}
}
if ($(`${toHide.join()}`).length) {
$(`${toHide.join()}`).parent(".field").addClass("d-none");
}
}
}
134 changes: 134 additions & 0 deletions assets/legacy/js/sylius-form-collection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

import $ from 'jquery';

/**
* Collection Form plugin
*
* @param element
* @constructor
*/
class CollectionForm {
constructor(element) {
this.addItem = this.addItem.bind(this);
this.updateItem = this.updateItem.bind(this);
this.deleteItem = this.constructor.deleteItem;
this.updatePrototype = this.updatePrototype.bind(this);

this.$element = $(element);
this.$list = this.$element.find('[data-form-collection="list"]:first');
this.count = this.$list.children().length;
this.lastChoice = null;
this.$element.on('click', '[data-form-collection="add"]:last', this.addItem);
this.$element.on('click', '[data-form-collection="delete"]', this.deleteItem);
this.$element.on('change', '[data-form-collection="update"]', this.updateItem);
$(document).on('change', '[data-form-prototype="update"]', this.updatePrototype);
$(document).on('collection-form-add', (event, addedElement) => {
$(addedElement).find('[data-form-type="collection"]').CollectionForm();
$(document).trigger('dom-node-inserted', [$(addedElement)]);
});
}

/**
* Add a item to the collection.
* @param event
*/
addItem(event) {
event.preventDefault();

let prototype = this.$element.data('prototype');
let prototypeName = new RegExp(this.$element.data('prototype-name'), 'g');

prototype = prototype.replace(prototypeName, this.count);

this.$list.append(prototype);
this.count = this.count + 1;

$(document).trigger('collection-form-add', [this.$list.children().last()]);
}

/**
* Update item from the collection
*/
updateItem(event) {
event.preventDefault();
const $element = $(event.currentTarget);
const url = $element.data('form-url');
const value = $element.val();
const $container = $element.closest('[data-form-collection="item"]');
const index = $container.data('form-collection-index');
const position = $container.data('form-collection-index');

if (url) {
$container.load(url, { id: value, position });
} else {
let $prototype = this.$element.find(`[data-form-prototype="${value}"]`);
let prototypeName = new RegExp($prototype.data('subprototype-name'), 'g');

let prototype = $prototype.val().replace(prototypeName, index);

$container.replaceWith(prototype);
}
$(document).trigger('collection-form-update', [$(event.currentTarget)]);
}

/**
* Delete item from the collection
* @param event
*/
static deleteItem(event) {
event.preventDefault();

$(event.currentTarget)
.closest('[data-form-collection="item"]')
.remove();

$(document).trigger('collection-form-delete', [$(event.currentTarget)]);
}

/**
* Update the prototype
* @param event
*/
updatePrototype(event) {
const $target = $(event.currentTarget);
let prototypeName = $target.val();

if ($target.data('form-prototype-prefix') !== undefined) {
prototypeName = $target.data('form-prototype-prefix') + prototypeName;
}

if (this.lastChoice !== null && this.lastChoice !== prototypeName) {
this.$list.html('');
}

this.lastChoice = prototypeName;

this.$element.data('prototype', this.$element.find(`[data-form-prototype="${prototypeName}"]`).val());
}
}

/*
* Plugin definition
*/

$.fn.CollectionForm = function CollectionFormPlugin(option) {
this.each((idx, el) => {
const $element = $(el);
const data = $element.data('collectionForm');
const options = typeof option === 'object' && option;

if (!data) {
$element.data('collectionForm', new CollectionForm(el, options));
}
});
};

$.fn.CollectionForm.Constructor = CollectionForm;
38 changes: 27 additions & 11 deletions assets/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"name": "synolia-sylius-akeneo-plugin",
"version": "1.0.0",
"name": "@synolia/sylius-akeneo-plugin",
"version": "2.0.0",
"keywords": [
"symfony-ux"
],
"description": "Synolia Sylius Akeneo PIM Plugin",
"source": "src/main.js",
"type": "module",
"files": [
"dist"
],
"repository": "git@bitbucket.org:synolia/sylius-akeneo-plugin.git",
"license": "MIT",
"private": true,
"scripts": {
"build": "parcel build src/main.js src/js/form.js src/js/tooltip.js --dist-dir ../src/Resources/public --no-source-maps",
"dev": "parcel watch src/main.js src/js/form.js src/js/tooltip.js --dist-dir ../tests/Application/public/bundles/synoliasyliusakeneoplugin --no-hmr",
"eslint": "eslint -c .eslintrc ./",
"fix-eslint": "eslint -c .eslintrc ./ --fix"
},
Expand All @@ -17,18 +21,30 @@
"last 2 versions",
"not ie <= 8"
],
"symfony": {
"controllers": {
"form": {
"main": "controllers/form_controller.js",
"enabled": true,
"webpackMode": "lazy",
"fetch": "lazy"
}
}
},
"peerDependencies": {
"@hotwired/stimulus": "^3.0.0"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@parcel/transformer-sass": "^2.5.0",
"@hotwired/stimulus": "^3.0.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
"eslint-config-prettier": "^6.10.1",
"eslint-plugin-prettier": "^3.1.3",
"node-forge": "^1.3",
"parcel": "^2.5.0",
"prettier": "2.0.4",
"sass": "^1.26.3"
"prettier": "2.0.4"
},
"dependencies": {}
"dependencies": {
"jquery": "^3.5.1"
}
}
Loading
Loading