Skip to content

Commit

Permalink
Merge branch '4.0' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Sep 3, 2024
2 parents 86bf75b + da23b76 commit bb249da
Show file tree
Hide file tree
Showing 39 changed files with 937 additions and 706 deletions.
1 change: 1 addition & 0 deletions .github/workflows/behat_ui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
PIMCORE_INSTALL_MYSQL_PORT: "3306"
PANTHER_EXTERNAL_BASE_URI: "http://localhost:9080/index_test.php"
PANTHER_CHROME_ARGUMENTS: "--disable-dev-shm-usage"
PANTHER_DEVTOOLS: "0"
PIMCORE_KERNEL_CLASS: 'Kernel'

strategy:
Expand Down
5 changes: 2 additions & 3 deletions docs/03_Bundles/Menu_Bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function registerBundlesToCollection(BundleCollection $collection)

```php
<?php
namespace AppBundle\Menu;
namespace App\CoreShop\Menu;

use CoreShop\Bundle\MenuBundle\Builder\MenuBuilderInterface;
use Knp\Menu\FactoryInterface;
Expand All @@ -60,8 +60,7 @@ public function registerBundlesToCollection(BundleCollection $collection)
Register your menu builder class in the Symfony container.

```yml
app.my_menu:
class: AppBundle\Menu\MyMenuBuilder
App\CoreShop\Menu\MyMenuBuilder:
tags:
- { name: coreshop.menu, type: my_menu, menu: my_menu }
```
Expand Down
2 changes: 1 addition & 1 deletion docs/03_Bundles/Pimcore_Bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ the `CoreShop\Component\Pimcore\Event\SlugGenerationEvent` Event.

declare(strict_types=1);

namespace App\EventListener;
namespace App\CoreShop\EventListener;

use CoreShop\Component\Pimcore\Event\SlugGenerationEvent;
use Pimcore\Model\DataObject\PressRelease;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

### PimcoreEntity

Create PimcoreEntity.php in the AppBundle/Model directory.
Create PimcoreEntity.php in the App/Model directory.

```php
<?php
// AppBundle/Model/PimcoreEntity.php
// App/Model/PimcoreEntity.php

namespace AppBundle\Model;
namespace App\Model;

use CoreShop\Bundle\ResourceBundle\Attribute\AsPimcoreModel;
use CoreShop\Component\Resource\Pimcore\Model\AbstractPimcoreModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

### PimcoreEntity

Create PimcoreEntity.php in the AppBundle/Model directory.
Create PimcoreEntity.php in the App/Model directory.

```php
<?php
// AppBundle/Model/PimcoreEntity.php
// App/Model/PimcoreEntity.php

abstract class PimcoreEntity extends AbstractPimcoreModel implements PimcoreModelInterface
{
Expand Down
2 changes: 1 addition & 1 deletion docs/03_Bundles/Resource_Bundle/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jms_serializer:
```yaml
# config/jms_serializer/CustomEntity.yml
AppBundle\Model\CustomEntity:
App\Model\CustomEntity:
exclusion_policy: ALL
xml_root_name: custom_entity
properties:
Expand Down
9 changes: 4 additions & 5 deletions docs/03_Bundles/SEO_Bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Implement a custom extractor for the Product class:

```php
<?php
// src/AppBundle/SEO/Extractor/ProductVideoExtractor.php
// src/App/CoreShop/SEO/Extractor/ProductVideoExtractor.php

namespace AppBundle\SEO\Extractor;
namespace App\CoreShop\SEO\Extractor;

//...

Expand All @@ -69,12 +69,11 @@ final class ProductVideoExtractor implements ExtractorInterface
}
```

Register the service in your `services.yml`:
Register the service in your `config/services.yaml`:

```yml
# src/AppBundle/Resources/config/services.yml
services:
AppBundle\SEO\Extractor\ProductVideoExtractor:
App\CoreShop\SEO\Extractor\ProductVideoExtractor:
tags:
- { name: coreshop.seo.extractor, type: product_video }
```
Expand Down
117 changes: 52 additions & 65 deletions docs/03_Development/01_Extending_Guide/01_Extend_CoreShop_Resources.md
Original file line number Diff line number Diff line change
@@ -1,126 +1,113 @@
# Extend CoreShop Resources

All models in Coreshop are placed in the `Coreshop\Component\*ComponentName*\Model` namespaces alongside with their
interfaces.
All models in Coreshop are placed in the ```Coreshop\Component\*ComponentName*\Model``` namespaces alongside with their interfaces.

> Many models in CoreShop are extended in the Core component. If the model you are willing to override exists in the
> Core you should be extending the Core one, not the base model from the component.
> Many models in CoreShop are extended in the Core component. If the model you are willing to override exists in the Core you should be extending the Core one, not the base model from the component.
## How to Customize a Model

First things first: If you want to extend coreshop models your Bundle must extend the `AbstractResourceBundle`. Next you
have set your supported drivers. Just add the following lines of code to your bundle class:
### Doctrine ORM

```php
public function getSupportedDrivers(): array
{
return [
CoreShopResourceBundle::DRIVER_DOCTRINE_ORM
];
}
```

After that have to tell the bundle where your models are. For that, add the override the following method in your bundle
class and return the model namespace. Here is an example for the `AppBundle`:
Depending on your Doctrine ORM configuration, you need to place your Models in the right Folder. The Default configuration, places them in the `Entity` directory:

```php
protected function getModelNamespace(): string
{
return "AppBundle\Model";
}
```yaml
doctrine:
orm:
mappings:
App:
type: attribute
dir: '%kernel.project_dir%/src/App/Entity'
is_bundle: false
prefix: App\Entity
alias: App
```
Here a quick overview for you which directories are important for you, when customizing CoreShop models.
### Example Model
| Folder | Description |
|-------------------------------------------|-----------------------------------------------|
| `AcmeBundle/Model` or `AcmeBundle/Entity` | Where your models are living |
| `AcmeBundle/config/doctrine/model` | Put your doctrine `.yml` config files in here |
| `AcmeBundle/config/serializer` | The serializer configs for the models |

Let’s take the `CoreShop\Component\Currency\Model\Currency` as an example. This one is extended in Core. How can you
check that?
Let’s take the [```CoreShop\Component\Currency\Model\Currency```](https://github.com/coreshop/CoreShop/blob/master/src/CoreShop/Component/Currency/Model/Currency.php) as an example. This one is extended in Core. How can you check that?

First of all, you need to find the current used class by doing following:

```bash
$ php bin/console debug:container --parameter=coreshop.model.currency.class
```

As a result you will get the `CoreShop\Component\Core\Model\Currency` - this is the class that you need to be extending.
As a result you will get the [```CoreShop\Component\Core\Model\Currency```](https://github.com/coreshop/CoreShop/blob/master/src/CoreShop/Component/Core/Model/Currency.php) - this is the class that you need to be extending.

Assuming you want to add a field called **flag**:
Assuming you want to add a field called **flag**

**1.** The first thing to do is to write your own class which will extend the base `Currency` class:
**1.** The first thing to do is to write your own class which will extend the base ```Currency``` class

```php
<?php
namespace AppBundle\Entity;
namespace App\Entity;
use CoreShop\Component\Core\Model\Currency as BaseCurrency;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="coreshop_currency")
*/
class Currency extends BaseCurrency
{
/**
* @var bool
* @ORM\Column(type="boolean")
*/
private $flag;
private bool $flag = false;
/**
* @return bool
*/
public function getFlag()
public function getFlag(): bool
{
return $this->flag;
}
/**
* @param bool $flag
*/
public function setFlag($flag)
public function setFlag(bool $flag): void
{
$this->flag = $flag;
}
}
```

**2.** Next define your entity’s mapping. The file should be placed
in `AppBundle/Resources/config/doctrine/Currency.orm.yml`:

```yaml
AppBundle\Entity\Currency:
type: mappedSuperclass
table: coreshop_currency
fields:
flag:
type: boolean
nullable: true
```
**2**. Finally you’ll need to override the model’s class in the ```config/config.yaml```.

**3.** Finally, you’ll need to override the model’s class in the `app/config/config.yml`.
Under the core_shop_* where * is the name of the bundle of the model you are customizing, in our case it will be the CoreShopCurrencyBundle -> core_shop_currency.

Under the `core_shop_currency`, modify as follows:

```yaml
core_shop_currency:
resources:
currency:
classes:
model: AppBundle\Entity\Currency
resources:
currency:
classes:
model: App\Entity\Currency
```

**4.** Update the database. There are two ways to do it:
**3**. Update the database. There are two ways to do it.

via direct database schema update:

```bash
$ php bin/console doctrine:schema:update --force
```

via migrations (recommended):
via migrations:
Which we strongly recommend over updating the schema.

```bash
$ php bin/console doctrine:migrations:diff
$ php bin/console doctrine:migrations:migrate
```

**4**. We also need a serializer group for the new field. This is done in the ```config/jms_serializer/Currency.yaml``` file.

```yaml
App\Entity\Currency:
exclusion_policy: ALL
xml_root_name: store
properties:
flag:
expose: true
type: bool
groups: [Detailed]
```
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Customizing Forms

The forms in CoreShop are placed in the `CoreShop\Bundle\*BundleName*\Form\Type` namespaces and the extensions will be
placed in `AppBundle\Form\Extension`.
placed in `App\CoreShop\Form\Extension`.

## Why would you customize a Form?

Expand Down Expand Up @@ -46,7 +46,7 @@ this is the class that you need to be extending.
```php
<?php

namespace AppBundle\Form\Extension;
namespace App\CoreShop\Form\Extension;

use CoreShop\Bundle\StoreBundle\Form\Type\StoreType;
use Symfony\Component\Form\AbstractTypeExtension;
Expand All @@ -70,17 +70,16 @@ final class StoreTypeExtension extends AbstractTypeExtension
}
```

**3.** After creating your class, register this extension as a service in the `AppBundle/Resources/config/services.yml`:
**3.** After creating your class, register this extension as a service in the `config/services.yaml`:

```yaml
services:
app.form.extension.type.customer_profile:
class: AppBundle\Form\Extension\StoreTypeExtension
App\CoreShop\Form\Extension\StoreTypeExtension:
tags:
- { name: form.type_extension, extended_type: CoreShop\Bundle\StoreBundle\Form\Type\StoreType }
```
In our case you will need to extend the ExtJs Form as well: `src/AppBundle/Resources/public/pimcore/js/store.js`.
In our case you will need to extend the ExtJs Form as well: `public/coreshop/js/store.js`.

In **ExtJs** your new store file need to look like this:

Expand Down Expand Up @@ -111,5 +110,5 @@ And you need to configure it to be loaded as well:
core_shop_store:
pimcore_admin:
js:
custom_store: '/bundles/app/pimcore/js/store.js'
custom_store: '/coreshop/js/store.js'
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ core_shop_order:
order:
classes:
model: 'Pimcore\Model\DataObject\MyOrderClass'
install_file: '@AppBundle/Resources/install/pimcore/classes/MyOrderClass.json'
repository: AppBundle\Repository\OrderRepository
factory: AppBundle\Factory\OrderFactory
install_file: 'config/Resources/install/pimcore/classes/MyOrderClass.json'
repository: App\Repository\OrderRepository
factory: App\Factory\OrderFactory
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ Rules, we need to use
[```CoreShop\Component\Product\Rule\Action\ProductPriceActionProcessorInterface```](https://github.com/coreshop/CoreShop/blob/master/src/CoreShop/Component/Product/Rule/Action/ProductPriceActionProcessorInterface.php)

```php
//AppBundle/CoreShop/CustomAction.php
namespace AppBundle\CoreShop;
namespace App\CoreShop;

final class CustomAction implements \CoreShop\Component\Product\Rule\Action\ProductPriceActionProcessorInterface
{
Expand All @@ -38,18 +37,14 @@ We also need a FormType for the actions configurations:

```php
<?php
//AppBundle/Form/Type/CustomActionType.php
namespace AppBundle\Form\Type;
namespace App\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;

final class CustomActionType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
Expand All @@ -62,7 +57,7 @@ final class CustomActionType extends AbstractType
With configuration, comes a Javascript file as well:

```javascript
//AppBundle/Resources/public/pimcore/js/custom_action.js
// public/coreshop/js/custom_action.js

pimcore.registerNS('coreshop.product.pricerule.actions.custom');
coreshop.product.pricerule.actions.custom = Class.create(coreshop.rules.actions.abstract, {
Expand Down Expand Up @@ -107,10 +102,9 @@ bin/console assets:install web
We now need to create our Service Definition for our Custom Action:

```yaml
app.product_price_rule.custom:
class: AppBundle\CoreShop\CustomAction
App\CoreShop\CustomAction:
tags:
- { name: coreshop.product_price_rule.action, type: custom, form-type: AppBundle\Form\Type\CustomActionType }
- { name: coreshop.product_price_rule.action, type: custom, form-type: App\CoreShop\Form\Type\CustomActionType }
```
and add this to your config.yml:
Expand All @@ -119,5 +113,5 @@ and add this to your config.yml:
core_shop_product:
pimcore_admin:
js:
custom_action: '/bundles/app/pimcore/js/custom_action.js'
custom_action: '/coreshop/js/custom_action.js'
```
Loading

0 comments on commit bb249da

Please sign in to comment.