OroCommerce give ability to start checkout from multi source like shopping list or order itself by re-order , So the entity source for checkout should implement CheckoutSourceEntityInterface , like Order and ShoppingList entities . And Checkout entity has relation with entity CheckoutSource.
You can start create you custom source of checkout by adding relation between you custom entity and CheckoutSource entity by migration , let’s give you custom entity a name of CustomSource
Example of your full class migration:
<?php namespace Ibnab\Bundle\CustomBundle\Migrations\Schema\v1_1; use Doctrine\DBAL\Schema\Schema; use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope; use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope; use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension; use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface; use Oro\Bundle\MigrationBundle\Migration\QueryBag; use Oro\Bundle\MigrationBundle\Migration\Migration; class IbnabCustomBundle implements Migration, ExtendExtensionAwareInterface { /** * @var ExtendExtension */ protected $extendExtension;</p> <p> /** * {@inheritdoc} */ public function setExtendExtension(ExtendExtension $extendExtension) { $this->extendExtension = $extendExtension; } /** * {@inheritdoc} */ public function up(Schema $schema, QueryBag $queries) { /** Tables generation **/</p> <p> $this->addCustomSourceCheckoutSource($schema); } protected function addCustomSourceCheckoutSource(Schema $schema) { $this->extendExtension->addManyToOneRelation( $schema, 'oro_checkout_source', 'customSource', 'ibnab_custom_source', 'id', [ 'entity' => ['label' => 'ibnab.ordertemplate.entity_label'], 'extend' => [ 'is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM ], 'datagrid' => [ 'is_visible' => DatagridScope::IS_VISIBLE_FALSE, ], 'form' => [ 'is_enabled' => false ], 'view' => ['is_displayable' => false], 'merge' => ['display' => false], 'dataaudit' => ['auditable' => false] ] ); } }</p> <p>}
As CheckoutSource is an extend entity we have add custom relation with Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension to your CustomSource entity, now oroplatfrom will add addCustomSource function to CheckoutSource by configuration inside cache .
You can explore manyToOne relation details inside oro_entity_config by simple select sql query and filter by class_name=’Oro\Bundle\CheckoutBundle\Entity\CheckoutSource’ so you will get a result just unserialize content of field data by :
$data = $this->connection->convertToPHPValue($row['data'], Type::TARRAY);
The result of extraction from full result:
["manyToOne|Oro\Bundle\CheckoutBundle\Entity\CheckoutSource|Ibnab\Bundle\CustomBundle\Entity\CustomSource|customSource"]=> ["field_id"]=> object(Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId)#41948 (4) { ["scope":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=> string(6) "extend" ["className":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=> string(47) "Oro\Bundle\CheckoutBundle\Entity\CheckoutSource" ["fieldName":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=> string(13) "orderTemplate" ["fieldType":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=> string(9) "manyToOne" } ["owner"]=> bool(true) ["target_entity"]=> string(53) "Ibnab\Bundle\CustomBundle\Entity\CustomSource" ["target_field_id"]=> bool(false) ["nullable"]=> bool(true) } } ["schema"]=> ["class"]=> string(47) "Oro\Bundle\CheckoutBundle\Entity\CheckoutSource" ["entity"]=> string(49) "Extend\Entity\EX_OroCheckoutBundle_CheckoutSource" ["type"]=> string(6) "Extend" ["property"]=> ["serialized_data"]=> } } ["relation"]=> ["order"]=> } ["quoteDemand"]=> } ["shoppingList"]=> } ["customSource"]=> } }
You can create your Entity CustomSource Based on Oro\Bundle\ShoppingListBundle\Entity\ShoppingList , should has relation OneToMany with your LineItem which you can create for example based on Oro\Bundle\ShoppingListBundle\Entity\LineItem .
So now is the time to create converter of LineItem for your CustomSource to Checkout with service tagged as oro.checkout.line_item.converter example:
ibnab_custom_source.line_item.converter.order_template: class: 'Ibnab\Bundle\CustomBundle\Converter\CustomSourceLineItemConverter' tags: - { name: oro.checkout.line_item.converter, alias: custom_source }
Your can get an example of code for you class CustomSourceLineItemConverter from Oro\Bundle\CheckoutBundle\Converter\ShoppingListLineItemConverter
So now you can create an action to create order from your custom source and example inside src/Ibnab/Bundle/CustomBundle/Resources/config/oro/actions.yml:
action_groups: start_custom_source_checkout: parameters: customSource: type: Ibnab\Bundle\CustomBundle\Entity\CustomSource actions: - '@run_action_group': action_group: start_checkout parameters_mapping: sourceCriteria: orderTemplate: $.customSource settings: allow_manual_source_remove: false remove_source: false showErrors: true validateOnStartCheckout: true force: true forceStartCheckout: true results: redirectUrl: $.redirectUrl checkout: $.checkout errors: $.errors
IS done is a big points of how to create your custom source to start checkout .
Comments