Resource Bundle
The Resource Bundle is a central component of CoreShop, handling the creation, reading, updating, and deleting (CRUD) of CoreShop models. It manages Doctrine ORM mappings, translations, routing, event dispatching, serialization, and CRUD operations. This bundle also facilitates the installation of various Pimcore definitions.
Installation Process
To install the Resource Bundle, use Composer:
$ composer require coreshop/resource-bundle:^4.0
Integrating with the Kernel
Enable the bundle in the kernel by updating the AppKernel.php
file:
<?php
// app/AppKernel.php
public function registerBundlesToCollection(BundleCollection $collection)
{
$collection->addBundles([
new \CoreShop\Bundle\ResourceBundle\CoreShopResourceBundle(),
]);
}
Adding Custom Doctrine Entities
To create custom entities or extend existing CoreShop Doctrine entities:
-
Enable Doctrine ORM:
# app/config/config.yml
doctrine:
orm:
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App -
Create Your Entity:
# src/Entity/CustomEntity.php
<?php
declare(strict_types=1);
namespace App\Entity;
// Entity implementation -
Register as a CoreShop Resource:
# app/config/config.yml
core_shop_resource:
resources:
app.custom_entity:
classes:
model: App\Entity\CustomEntity
interface: CoreShop\Component\Resource\Model\ResourceInterface
repository: CoreShop\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository -
Configure Routes:
# config/routes.yaml
coreshop_admin_custom_entity:
type: coreshop.resources
resource: |
alias: app.custom_entity
# additional routes -
Configure Serializer:
# app/config/config.yml
jms_serializer:
metadata:
directories:
app:
namespace_prefix: "App\\Entity"
path: "%kernel.project_dir%/config/jms_serializer"# config/jms_serializer/CustomEntity.yml
AppBundle\Model\CustomEntity:
exclusion_policy: ALL
xml_root_name: custom_entity
properties:
id:
expose: true
type: integer
groups: [List, Detailed]
name:
expose: true
type: array
groups: [List, Detailed]
Adding Custom Pimcore Entities
Similar to Doctrine entities, you can register Pimcore DataObject Classes:
-
Model Implementation:
Extend from
CoreShop\Component\Resource\Pimcore\Model\AbstractPimcoreModel
or implementCoreShop\Component\Resource\Model\ResourceInterface
. -
Register as CoreShop Resource:
# app/config/config.yml
core_shop_resource:
pimcore:
app.my_data_object_class:
classes:
model: Pimcore\Model\DataObject\MyDataObjectClass
interface: CoreShop\Component\Resource\Model\ResourceInterface -
Usage: Utilize CoreShop's repository service or Pimcore's listing classes for data manipulation and retrieval.
The Resource Bundle is the backbone of CoreShop, enhancing its capabilities and providing a robust framework for managing models and data in Pimcore.