Skip to content

Commit

Permalink
BB-20150: Move the AlternativeCheckoutBundle to a separate package
Browse files Browse the repository at this point in the history
- added the package directory, README, composer, etc.
  • Loading branch information
Mykhailo Sulyma authored and EugeneC committed Dec 28, 2020
0 parents commit b097895
Show file tree
Hide file tree
Showing 37 changed files with 2,932 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Please refer first to [UPGRADE.md](UPGRADE.md) for the most important items that should be addressed before attempting to upgrade or during the upgrade of a vanilla Oro application.

The current file describes significant changes in the code that may affect the upgrade of your customizations.

## 4.2.0

OroAlternativeCheckoutBundle has been moved from oro/commerce package to oro/commerce-demo-checkouts package.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OroCommerce

The Open Software License version 3.0

Copyright (c) 2020, Oro, Inc.

Full license is at: http://opensource.org/licenses/OSL-3.0
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
OroCommerce Checkout Customization Examples
===========================================

This package includes examples of OroCommerce storefront checkout customizations.

OroAlternativeCheckoutBundle
----------------------------

OroAlternativeCheckoutBundle adds review and approval steps to the checkout workflow in the OroCommerce storefront if the order amount exceeds the order approval threshold value set by an application administrator in the alternative checkout workflow configuration UI.

Installation
------------

This package can be added to an existing installation of an OroCommerce application.

Use composer to add the package code:

```
composer require oro/commerce-demo-checkouts
```

Perform the installation:

```
php bin/console oro:platform:update --env=prod
```
3 changes: 3 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This file includes only the most important items that should be addressed before attempting to upgrade or during the upgrade of a vanilla Oro application.

Please refer to [CHANGELOG.md](CHANGELOG.md) for a list of significant changes in the code that may affect the upgrade of some customizations.
32 changes: 32 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "oro/commerce-demo-checkouts",
"description": "OroCommerce checkout customization examples",
"homepage": "https://github.com/oroinc/commerce-demo-checkouts",
"license": "OSL-3.0",
"authors": [
{
"name": "Oro, Inc",
"homepage": "https://www.orocommerce.com"
}
],
"autoload": {
"psr-4": {"Oro\\Bundle\\AlternativeCheckoutBundle\\": "src/Oro/Bundle/AlternativeCheckoutBundle"},
"exclude-from-classmap": ["/Tests/"]
},
"require": {
"oro/commerce": "4.2.*"
},
"repositories": {
"oro": {
"type": "composer",
"url": "https://packagist.oroinc.com"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "4.2-dev"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle\Condition;

use Oro\Bundle\CheckoutBundle\DataProvider\Manager\CheckoutLineItemsManager;
use Oro\Bundle\OrderBundle\Entity\Order;
use Oro\Bundle\PricingBundle\SubtotalProcessor\TotalProcessorProvider;
use Oro\Component\ConfigExpression\Condition\AbstractComparison;

/**
* Checks that order with subtotal exceeding the specified value.
*
* Usage:
* '@less_order_total_limit':
* - $checkout # any instance of the Checkout entity
* - 5000 # the value of the order approval threshold
*/
class OrderTotalLimit extends AbstractComparison
{
private TotalProcessorProvider $totalsProvider;
private CheckoutLineItemsManager $checkoutLineItemsManager;

/**
* @param TotalProcessorProvider $totalsProvider
* @param CheckoutLineItemsManager $checkoutLineItemsManager
*/
public function __construct(
TotalProcessorProvider $totalsProvider,
CheckoutLineItemsManager $checkoutLineItemsManager
) {
$this->totalsProvider = $totalsProvider;
$this->checkoutLineItemsManager = $checkoutLineItemsManager;
}

/**
* {@inheritdoc}
*/
public function getName(): string
{
return 'less_order_total_limit';
}

/**
* {@inheritdoc}
*/
protected function isConditionAllowed($context): bool
{
return $this->doCompare(
$this->resolveValue($context, $this->left),
$this->resolveValue($context, $this->right)
);
}

/**
* {@inheritdoc}
*/
protected function doCompare($left, $right): bool
{
$orderLineItems = $this->checkoutLineItemsManager->getData($left);
$order = new Order();
$order->setLineItems($orderLineItems);

$orderTotalAmount = $this->totalsProvider->enableRecalculation()->getTotal($order)->getAmount();

return $orderTotalAmount <= $right;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* Loads service definitions.
*/
class OroAlternativeCheckoutExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle\EventListener;

use Oro\Bundle\InventoryBundle\EventListener\QuantityToOrderConditionListener as BaseListener;

/**
* Handles line items inventory validation events of the alternative checkout workflow.
*/
class QuantityToOrderConditionListener extends BaseListener
{
/** @var array */
protected const ALLOWED_WORKFLOWS = [
'b2b_flow_alternative_checkout',
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle\Migrations\Data\Demo\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Oro\Bundle\CustomerBundle\Migrations\Data\Demo\ORM\LoadCustomerDemoData;
use Oro\Bundle\WorkflowBundle\Entity\WorkflowDefinition;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

/**
* Aсtivates the alternative checkout workflow.
*/
class UpdateAlternativeCheckoutWorkflowStatus extends AbstractFixture implements
DependentFixtureInterface,
ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* {@inheritdoc}
*/
public function getDependencies(): array
{
return [LoadCustomerDemoData::class];
}

/**
* {@inheritdoc}
*/
public function load(ObjectManager $manager): void
{
/** @var WorkflowDefinition $workflowDefinition */
$workflowDefinition = $manager->getRepository('OroWorkflowBundle:WorkflowDefinition')
->find('b2b_flow_alternative_checkout');

if (!$workflowDefinition) {
return;
}

$this->container->get('oro_workflow.manager.system')->activateWorkflow($workflowDefinition->getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ACME_BUYER:
permissions:
action|oro_alternativecheckout_checkout_approve: [NONE]
workflow|b2b_flow_alternative_checkout: [VIEW_WORKFLOW_BASIC, PERFORM_TRANSITIONS_BASIC]

ACME_ADMINISTRATOR:
permissions:
workflow|b2b_flow_alternative_checkout: [VIEW_WORKFLOW_DEEP, PERFORM_TRANSITIONS_DEEP]

ACME_ANONYMOUS:
permissions:
workflow|b2b_flow_alternative_checkout: [VIEW_WORKFLOW_BASIC, PERFORM_TRANSITIONS_BASIC]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle\Migrations\Data\ORM;

use Oro\Bundle\CustomerBundle\Migrations\Data\ORM\AbstractMassUpdateCustomerUserRolePermissions;

/**
* Update workflow default permissions for predefined roles.
*/
class UpdateWorkflowsPermissions extends AbstractMassUpdateCustomerUserRolePermissions
{
/**
* {@inheritdoc}
*/
protected function getACLData(): array
{
return [
'ROLE_FRONTEND_ADMINISTRATOR' => [
'workflow:b2b_flow_alternative_checkout' => ['VIEW_WORKFLOW_DEEP', 'PERFORM_TRANSITIONS_DEEP']
],
'ROLE_FRONTEND_BUYER' => [
'workflow:b2b_flow_alternative_checkout' => ['VIEW_WORKFLOW_BASIC', 'PERFORM_TRANSITIONS_BASIC']
],
'ROLE_FRONTEND_ANONYMOUS' => [
'workflow:b2b_flow_alternative_checkout' => ['VIEW_WORKFLOW_BASIC', 'PERFORM_TRANSITIONS_BASIC']
]
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BUYER:
permissions:
action|oro_alternativecheckout_checkout_approve: [NONE]
workflow|b2b_flow_alternative_checkout: [VIEW_WORKFLOW_BASIC, PERFORM_TRANSITIONS_BASIC]

ADMINISTRATOR:
permissions:
workflow|b2b_flow_alternative_checkout: [VIEW_WORKFLOW_DEEP, PERFORM_TRANSITIONS_DEEP]

ANONYMOUS:
permissions:
workflow|b2b_flow_alternative_checkout: [VIEW_WORKFLOW_BASIC, PERFORM_TRANSITIONS_BASIC]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle\Migrations\Schema;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Installation;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class OroAlternativeCheckoutBundleInstaller implements Installation
{
/**
* {@inheritdoc}
*/
public function getMigrationVersion(): string
{
return 'v1_4';
}

/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries): void
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);

namespace Oro\Bundle\AlternativeCheckoutBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

/**
* Bundle entry point
*/
class OroAlternativeCheckoutBundle extends Bundle
{
}
5 changes: 5 additions & 0 deletions src/Oro/Bundle/AlternativeCheckoutBundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# OroAlternativeCheckoutBundle

OroAlternativeCheckoutBundle adds seller approval steps to the checkout workflow in the OroCommerce storefront if the order amount exceeds the order approval threshold value set by an application administrator in the alternative checkout workflow configuration UI.

Note: The checkout workflow in the OroCommerce storefront helps gather necessary information from the customer when they are creating a new order.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
acls:
oro_alternativecheckout_checkout_approve:
label: oro.alternativecheckout.security.permission.checkout_approve
type: action
group_name: "commerce"
category: "checkout"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundles:
- { name: Oro\Bundle\AlternativeCheckoutBundle\OroAlternativeCheckoutBundle, priority: 60 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
datagrids:
frontend-customer-user-shopping-lists-grid:
action_configuration:
b2b_flow_alternative_checkout_start_from_shoppinglist: false

frontend-customer-user-shopping-list-select-grid:
action_configuration:
b2b_flow_alternative_checkout_start_from_shoppinglist: false
Loading

0 comments on commit b097895

Please sign in to comment.