Skip to content

Commit

Permalink
Merge pull request #13 from BitBagCommerce/OP-450
Browse files Browse the repository at this point in the history
OP-450 Added Sylius 1.13 support
  • Loading branch information
senghe authored Aug 13, 2024
2 parents 19577b2 + 49d41fb commit 5edb76c
Show file tree
Hide file tree
Showing 69 changed files with 538 additions and 521 deletions.
26 changes: 11 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,23 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0]
symfony: [^5.4, ^6.0]
sylius: [~1.11.0, ~1.12.0]
node: [14.x]
mysql: [5.7, 8.0]

php: ["8.0", "8.1", "8.2", "8.3"]
symfony: ["^5.4", "^6.0"]
sylius: ["~1.12.0", "~1.13.0"]
node: ["20.x"]
mysql: ["5.7", "8.0"]
exclude:
- # Segmentation fault while clearing cache
php: 8.0
mysql: 5.7
-
sylius: ~1.11.0
symfony: ^6.0
- sylius: "~1.13.0"
php: "8.0"

env:
APP_ENV: test
DATABASE_URL: "mysql://root:[email protected]/sylius?serverVersion=${{ matrix.mysql }}"

steps:
-
uses: actions/checkout@v2
uses: actions/checkout@v3

-
name: Setup PHP
Expand All @@ -52,7 +48,7 @@ jobs:

-
name: Setup Node
uses: actions/setup-node@v1
uses: actions/setup-node@v4
with:
node-version: "${{ matrix.node }}"

Expand Down Expand Up @@ -150,7 +146,7 @@ jobs:
name: Run PHPSpec
run: vendor/bin/phpspec run --ansi -f progress --no-interaction

-
-
name: Failed build Slack notification
uses: rtCamp/action-slack-notify@v2
if: ${{ failure() && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') }}
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ bitbag_sylius_shipping_subscription_plugin:
resource: "@BitBagSyliusShippingSubscriptionPlugin/Resources/config/routing.yml"
```


Extend `Product`(including Doctrine mapping):
If you want to extend entities via attribute mapping, see here: [Attributes](doc/attributes_mapping.md)

```php
<?php
Expand Down Expand Up @@ -347,7 +349,7 @@ Override forms by creating `templates/bundles/SyliusAdminBundle/Product/Tab/_det
{% if product.simple %}
{{ form_row(form.variant.shippingRequired) }}
{% else %}
{{ form_row(form.options) }}
{{ form_row(form.options, {'remote_url': path('sylius_admin_ajax_product_options_by_phrase'), 'load_edit_url': path('sylius_admin_ajax_find_product_options')}) }}
{{ form_row(form.variantSelectionMethod) }}
{% endif %}
Expand Down Expand Up @@ -457,7 +459,9 @@ Override forms by creating `templates/bundles/SyliusAdminBundle/Product/Tab/_det
</div>
```

`templates/bundles/SyliusAdminBundle/Product/ProductVariant/Tab/_details.html.twig`
`templates/bundles/SyliusAdminBundle/ProductVariant/Tab/_details.html.twig`

**Note.** Depending on your Sylius version, it may be `templates/bundles/SyliusAdminBundle/Product/ProductVariant/Tab/_details.html.twig` file path. Please check the path in your vendor directory.

```twig
{% from '@SyliusAdmin/Macro/translationForm.html.twig' import translationForm %}
Expand All @@ -479,8 +483,6 @@ Override forms by creating `templates/bundles/SyliusAdminBundle/Product/Tab/_det
<div class="two fields">
{{ form_row(form.shippingCategory) }}
</div>
{{form_label(form.channelPricings)}}
{% include "@SyliusAdmin/Product/_channel_pricing.html.twig" with { product: product_variant.product, variantForm: form } only %}
</div>
<div class="ui segment">
<div class="one field">
Expand Down
4 changes: 2 additions & 2 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default:
extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~

Lakion\Behat\MinkDebugExtension:
FriendsOfBehat\MinkDebugExtension:
directory: etc/build
clean_start: false
screenshot: true
Expand Down Expand Up @@ -46,7 +46,7 @@ default:
FriendsOfBehat\SymfonyExtension:
bootstrap: tests/Application/config/bootstrap.php
kernel:
class: Tests\Acme\SyliusExamplePlugin\Application\Kernel
class: Tests\BitBag\SyliusShippingSubscriptionPlugin\Application\Kernel

FriendsOfBehat\VariadicExtension: ~

Expand Down
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
"license": "MIT",
"require": {
"php": "^8.0",
"sylius/sylius": "~1.11.0 || ~1.12.0"
"sylius/sylius": "~1.12.0 || ~1.13.0"
},
"require-dev": {
"behat/behat": "^3.6.1",
"behat/mink-selenium2-driver": "^1.4",
"bitbag/coding-standard": "^1.0.1",
"behat/behat": "^3.7",
"behat/mink-selenium2-driver": "~1.6.0",
"bitbag/coding-standard": "^3.0",
"dmore/behat-chrome-extension": "^1.3",
"dmore/chrome-mink-driver": "^2.7",
"friends-of-behat/mink": "^1.8",
"friends-of-behat/mink-browserkit-driver": "^1.4",
"friends-of-behat/mink-debug-extension": "^2.0.0",
"friends-of-behat/mink-debug-extension": "^2.0",
"friends-of-behat/mink-extension": "^2.4",
"friends-of-behat/page-object-extension": "^0.3",
"friends-of-behat/suite-settings-extension": "^1.0",
"friends-of-behat/symfony-extension": "^2.1",
"friends-of-behat/variadic-extension": "^1.3",
"phpspec/phpspec": "^7.0",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "0.12.85",
"phpstan/phpstan-doctrine": "0.12.33",
"phpstan/phpstan-strict-rules": "^0.12.0",
"phpstan/phpstan-webmozart-assert": "0.12.12",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-strict-rules": "^1.3",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.5",
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
"symfony/browser-kit": "^5.4 || ^6.0",
Expand All @@ -48,6 +48,9 @@
"phpstan/extension-installer": true
}
},
"conflict": {
"doctrine/persistence": "<3.0"
},
"autoload": {
"psr-4": {
"BitBag\\SyliusShippingSubscriptionPlugin\\": "src/",
Expand Down
217 changes: 217 additions & 0 deletions doc/attributes_mapping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
## Attribute mapping settings

### Remember to mark attribute mapping appropriately in the config/doctrine.yaml configuration file.
```
// config/packages/doctrine.yaml
doctrine:
...
orm:
...
mappings:
App:
...
type: attribute
```
Extend Customer:
```php
<?php

declare(strict_types=1);

namespace App\Entity\Customer;

use BitBag\SyliusShippingSubscriptionPlugin\Entity\ShippingSubscription;
use BitBag\SyliusShippingSubscriptionPlugin\Entity\ShippingSubscriptionInterface;
use BitBag\SyliusShippingSubscriptionPlugin\Entity\SubscriptionAwareInterface;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Customer as BaseCustomer;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_customer")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_customer')]
class Customer extends BaseCustomer implements SubscriptionAwareInterface
{
#[ORM\OneToMany(mappedBy: 'customer', targetEntity: ShippingSubscription::class, orphanRemoval: true)]
protected Collection $shippingSubscriptions;

/** @return Collection<int, ShippingSubscriptionInterface>|null */
public function getSubscriptions(): ?Collection
{
return $this->shippingSubscriptions;
}
}
```

Extend Product:
```php
<?php

declare(strict_types=1);

namespace App\Entity\Product;

use BitBag\SyliusShippingSubscriptionPlugin\Entity\ProductShippingSubscriptionAwareInterface;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Product as BaseProduct;
use Sylius\Component\Product\Model\ProductTranslationInterface;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_product")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct implements ProductShippingSubscriptionAwareInterface
{
#[ORM\Column(type: 'boolean', options: ["default" => 0])]
protected bool $shippingSubscription;

public function isShippingSubscription(): bool
{
return $this->shippingSubscription;
}

public function setShippingSubscription(bool $shippingSubscription): void
{
$this->shippingSubscription = $shippingSubscription;
}

protected function createTranslation(): ProductTranslationInterface
{
return new ProductTranslation();
}
}
```

Extend ProductVariant:
```php
<?php

declare(strict_types=1);

namespace App\Entity\Product;

use BitBag\SyliusShippingSubscriptionPlugin\Entity\ProductVariantInterface;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\ProductVariant as BaseProductVariant;
use Sylius\Component\Product\Model\ProductVariantTranslationInterface;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_product_variant")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product_variant')]
class ProductVariant extends BaseProductVariant implements ProductVariantInterface
{
#[ORM\Column(type: 'integer', nullable: true, options: ['default' => 0])]
protected ?int $subscriptionLength;

public function getSubscriptionLength(): ?int
{
return $this->subscriptionLength;
}

public function setSubscriptionLength(?int $subscriptionLength): void
{
$this->subscriptionLength = $subscriptionLength;
}

protected function createTranslation(): ProductVariantTranslationInterface
{
return new ProductVariantTranslation();
}
}
```

Extend ShippingMethod:
```php
<?php

declare(strict_types=1);

namespace App\Entity\Shipping;

use BitBag\SyliusShippingSubscriptionPlugin\Entity\ShippingSubscriptionMethodInterface;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\ShippingMethod as BaseShippingMethod;
use Sylius\Component\Shipping\Model\ShippingMethodTranslationInterface;

/**
* @ORM\Entity
* @ORM\Table(name="sylius_shipping_method")
*/
#[ORM\Entity]
#[ORM\Table(name: 'sylius_shipping_method')]
class ShippingMethod extends BaseShippingMethod implements ShippingSubscriptionMethodInterface
{
#[ORM\Column(type: 'boolean', nullable: true, options: ['default' => 0])]
protected ?bool $shippingSubscription;

#[ORM\Column(type: 'integer', nullable: true)]
protected ?int $availableFromTotal;

public function getAvailableFromTotal(): ?int
{
return $this->availableFromTotal;
}

public function setAvailableFromTotal(?int $availableFromTotal): void
{
$this->availableFromTotal = $availableFromTotal;
}

public function isShippingSubscription(): ?bool
{
return $this->shippingSubscription;
}

public function setShippingSubscription(?bool $shippingSubscription): void
{
$this->shippingSubscription = $shippingSubscription;
}
protected function createTranslation(): ShippingMethodTranslationInterface
{
return new ShippingMethodTranslation();
}
}

```

Extend `OrderItemUnitRepository` (in src/Repository folder):

```php
<?php

declare(strict_types=1);

namespace App\Repository;

use BitBag\SyliusShippingSubscriptionPlugin\Repository\ShippingSubscriptionOrderRepositoryAwareInterface;
use BitBag\SyliusShippingSubscriptionPlugin\Repository\ShippingSubscriptionOrderRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\OrderItemUnitRepository as BaseOrderItemUnitRepository;

final class OrderItemUnitRepository extends BaseOrderItemUnitRepository implements ShippingSubscriptionOrderRepositoryAwareInterface
{
use ShippingSubscriptionOrderRepositoryTrait;
}
```

Add repository path into configuration `config/packages/_sylius.yaml`:

```yaml
sylius_order:
resources:
order_item_unit:
classes:
repository: App\Repository\OrderItemUnitRepository
```
### Go back to the main readme and override the Twig files.
[Open Readme](../README.md)
Loading

0 comments on commit 5edb76c

Please sign in to comment.