/   /   /  OroCommerce how to create checkout from custom source

Note:

For more extensions and themes visit our store

OroCommerce how to create checkout from custom source


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:

  1.  
  2. <?php
  3. namespace Ibnab\Bundle\CustomBundle\Migrations\Schema\v1_1;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Oro\Bundle\EntityBundle\EntityConfig\DatagridScope;
  6. use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
  7. use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtension;
  8. use Oro\Bundle\EntityExtendBundle\Migration\Extension\ExtendExtensionAwareInterface;
  9. use Oro\Bundle\MigrationBundle\Migration\QueryBag;
  10. use Oro\Bundle\MigrationBundle\Migration\Migration;
  11. class IbnabCustomBundle implements Migration, ExtendExtensionAwareInterface
  12. {
  13.     /**
  14.      * @var ExtendExtension
  15.      */
  16.     protected $extendExtension;</p>
  17.  
  18. <p>    /**
  19.      * {@inheritdoc}
  20.      */
  21.     public function setExtendExtension(ExtendExtension $extendExtension)
  22.     {
  23.         $this->extendExtension = $extendExtension;
  24.     }
  25.     /**
  26.      * {@inheritdoc}
  27.      */
  28.     public function up(Schema $schema, QueryBag $queries)
  29.     {
  30.         /** Tables generation **/</p>
  31.  
  32. <p>        $this->addCustomSourceCheckoutSource($schema);
  33.     }
  34.     protected function addCustomSourceCheckoutSource(Schema $schema)
  35.     {
  36.         if (class_exists('Oro\Bundle\CheckoutBundle\Entity\CheckoutSource')) {
  37.             $this->extendExtension->addManyToOneRelation(
  38.                 $schema,
  39.                 'oro_checkout_source',
  40.                 'customSource',
  41.                 'ibnab_custom_source',
  42.                 'id',
  43.                 [
  44.                     'entity' => ['label' => 'ibnab.ordertemplate.entity_label'],
  45.                     'extend' => [
  46.                         'is_extend' => true,
  47.                         'owner' => ExtendScope::OWNER_CUSTOM
  48.                     ],
  49.                     'datagrid' => [
  50.                         'is_visible' => DatagridScope::IS_VISIBLE_FALSE,
  51.                     ],
  52.                     'form' => [
  53.                         'is_enabled' => false
  54.                     ],
  55.                     'view' => ['is_displayable' => false],
  56.                     'merge' => ['display' => false],
  57.                     'dataaudit' => ['auditable' => false]
  58.                 ]
  59.             );
  60.         }
  61.     }</p>
  62.  
  63. <p>} 
  64.  

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: 

  1.       ["manyToOne|Oro\Bundle\CheckoutBundle\Entity\CheckoutSource|Ibnab\Bundle\CustomBundle\Entity\CustomSource|customSource"]=>
  2.       array(5) {
  3.         ["field_id"]=>
  4.         object(Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId)#41948 (4) {
  5.           ["scope":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=>
  6.           string(6) "extend"
  7.           ["className":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=>
  8.           string(47) "Oro\Bundle\CheckoutBundle\Entity\CheckoutSource"
  9.           ["fieldName":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=>
  10.           string(13) "orderTemplate"
  11.           ["fieldType":"Oro\Bundle\EntityConfigBundle\Config\Id\FieldConfigId":private]=>
  12.           string(9) "manyToOne"
  13.         }
  14.         ["owner"]=>
  15.         bool(true)
  16.         ["target_entity"]=>
  17.         string(53) "Ibnab\Bundle\CustomBundle\Entity\CustomSource"
  18.         ["target_field_id"]=>
  19.         bool(false)
  20.         ["nullable"]=>
  21.         bool(true)
  22.       }
  23.     }
  24.     ["schema"]=>
  25.     array(10) {
  26.       ["class"]=>
  27.       string(47) "Oro\Bundle\CheckoutBundle\Entity\CheckoutSource"
  28.       ["entity"]=>
  29.       string(49) "Extend\Entity\EX_OroCheckoutBundle_CheckoutSource"
  30.       ["type"]=>
  31.       string(6) "Extend"
  32.       ["property"]=>
  33.       array(1) {
  34.         ["serialized_data"]=>
  35.         array(0) {
  36.         }
  37.       }
  38.       ["relation"]=>
  39.       array(4) {
  40.         ["order"]=>
  41.         array(0) {
  42.         }
  43.         ["quoteDemand"]=>
  44.         array(0) {
  45.         }
  46.         ["shoppingList"]=>
  47.         array(0) {
  48.         }
  49.         ["customSource"]=>
  50.         array(0) {
  51.         }
  52.       }
  53.  

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:

  1.  
  2.     ibnab_custom_source.line_item.converter.order_template:
  3.         class: 'Ibnab\Bundle\CustomBundle\Converter\CustomSourceLineItemConverter'
  4.         tags:
  5.             - { name: oro.checkout.line_item.converter, alias: custom_source }
  6.  


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:

  1.  
  2. action_groups:
  3.     start_custom_source_checkout:
  4.         parameters:
  5.             customSource:
  6.                 type:  Ibnab\Bundle\CustomBundle\Entity\CustomSource
  7.         actions:
  8.             - '@run_action_group':
  9.                 action_group: start_checkout
  10.                 parameters_mapping:
  11.                     sourceCriteria:
  12.                         orderTemplate: $.customSource
  13.                     settings:
  14.                         allow_manual_source_remove: false
  15.                         remove_source: false
  16.                     showErrors: true
  17.                     validateOnStartCheckout: true
  18.                     force: true
  19.                     forceStartCheckout: true
  20.                 results:
  21.                     redirectUrl: $.redirectUrl
  22.                     checkout: $.checkout
  23.                     errors: $.errors
  24.  

IS done is a big points of how to create your custom source to start checkout .

Comments

Related Posts

make your store more efficient

Solving problems. With open source technology. Professional results. That’s what makes Ibnab your best choice

IBNAB is a company made of a group of professionals whose work is providing secure open source solutions. Our company strives for reaching magnificent results with each experience and provides professional open source solutions that cover every part of the business process.