Skip to content

Add customer address books in order creation view | Add webpack #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
611286d
add address book to create order form, include js and css files
BartoszWojdalowicz Jan 18, 2022
309852e
Add webpack encore to plugin
Jan 18, 2022
c2d7ec8
Add built assets, change plugin name
Jan 19, 2022
1633e6e
edit templates
BartoszWojdalowicz Mar 9, 2022
56d4561
add behat tests and modify existing
BartoszWojdalowicz Mar 9, 2022
1896935
Improved: OrderPaymentLinkSender
igormukhingmailcom Sep 10, 2020
d0d34de
Shouldn't have payment limit on order
kayue May 6, 2021
cd3fa75
Remove useless Migrations step from README.md
Dec 9, 2021
8396442
[Maintenance] Drop support for PHP 7.4
GSadee Feb 25, 2022
5ee743e
[Maintenance] Bump up support for Symfony 5 to 5.4 version
GSadee Feb 25, 2022
a929f1e
[Maintenance] Bump up node version in workflow
GSadee Feb 25, 2022
7796e5f
[Maintenance] Drop support for Sylius 1.9 + add for Sylius 1.11
GSadee Feb 25, 2022
f0300f6
Replace Zend PriorityQueue with Laminas PriorityQueue
GSadee Feb 25, 2022
8a516a8
[Maintenance] Add notes to UPGRADE file for 0.13.0
GSadee Feb 25, 2022
ab9353c
Fix state machine exception on order creation
maciekpaprocki Oct 13, 2021
7b232c3
added phpspec tests
maciekpaprocki Oct 28, 2021
8ae8979
Remove PHPUnit cache file
GSadee Feb 25, 2022
6bb2396
Generate changelog for v0.13.0
GSadee Feb 25, 2022
aa83615
Merge branch 'master' into feature/address-book
BartoszWojdalowicz Mar 9, 2022
bf152d5
Merge pull request #1 from BartoszWojdalowicz/feature/address-book
BartoszWojdalowicz Mar 9, 2022
5e7d64f
Merge branch 'master' of https://github.com/Sylius/AdminOrderCreation…
BartoszWojdalowicz Mar 9, 2022
79e1b42
Merge branch 'master' of https://github.com/BartoszWojdalowicz/AdminO…
BartoszWojdalowicz Mar 9, 2022
c1ca910
Remove public and resources public folders
Jul 19, 2023
a93811d
Remove redundant steps
Jul 19, 2023
7b74968
Transform script/style override to template event
Jul 19, 2023
b2eb3ec
Remove unused js import
Jul 19, 2023
f491521
Add webpack configuration in README.md
Jul 19, 2023
f8b917e
Fix resources does not exist in edit mode
Jul 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
/vendor/
/node_modules/
/composer.lock
/phpspec.yml

/etc/build/*
!/etc/build/.gitkeep
!/etc/build/.gitignore

/tests/Application/yarn.lock

Expand Down
65 changes: 57 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ Symfony Flex, it's much quicker! :)
2. Paste the following content to the `src/Repository/CustomerRepository.php`:
```php
<?php

declare(strict_types=1);

namespace App\Repository;

use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\CustomerRepositoryInterface;
use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\CustomerRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\CustomerRepository as BaseCustomerRepository;

final class CustomerRepository extends BaseCustomerRepository implements CustomerRepositoryInterface
{
use CustomerRepositoryTrait;
Expand All @@ -83,15 +83,15 @@ Symfony Flex, it's much quicker! :)
3. Paste the following content to the `src/Repository/ProductVariantRepository.php`:
```php
<?php

declare(strict_types=1);

namespace App\Repository;

use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\ProductVariantRepositoryInterface;
use Sylius\AdminOrderCreationPlugin\Doctrine\ORM\ProductVariantRepositoryTrait;
use Sylius\Bundle\CoreBundle\Doctrine\ORM\ProductVariantRepository as BaseProductVariantRepository;

final class ProductVariantRepository extends BaseProductVariantRepository implements ProductVariantRepositoryInterface
{
use ProductVariantRepositoryTrait;
Expand All @@ -105,15 +105,64 @@ Symfony Flex, it's much quicker! :)
classes:
model: App\Entity\Customer\Customer
+ repository: App\Repository\CustomerRepository

sylius_product:
resources:
product_variant:
classes:
model: App\Entity\Product\ProductVariant
+ repository: App\Repository\ProductVariantRepository
```

4. Add plugin assets to your project
1. Import webpack config
1. Import plugin's `webpack.config.js` file
```js
// webpack.config.js
const [ adminOrderCreationAdmin ] = require('./vendor/sylius/admin-order-creation-plugin/webpack.config.js')
...

module.exports = [..., adminOrderCreationAdmin];
```
2. Add new packages in `./config/packages/assets.yaml`
```yml
# config/packages/assets.yaml

framework:
assets:
packages:
# ...
admin_order_creation:
json_manifest_path: '%kernel.project_dir%/public/build/sylius/admin-order-creation/admin/manifest.json'
```

3. Add new build paths in `./config/packages/webpack_encore.yml`
```yml
# config/packages/webpack_encore.yml

webpack_encore:
builds:
# ...
admin_order_creation: '%kernel.project_dir%/public/build/sylius/admin-order-creation/admin'
```

2. Add entry to existing config
1. Add new entries to your `webpack.config.js`
```js
// ./webpack.config.js

// Admin config
.addEntry('sylius-order-creation-admin', 'vendor/sylius/admin-order-creation-plugin/src/Resources/assets/admin/entry.js')
```

2. Run `yarn encore dev` or `yarn encore production`

3. Import entries in your entry.js files
1. Just add these imports into your entry.js files
```js
// ./assets/admin/entry.js
import '../../vendor/sylius/admin-order-creation-plugin/src/Resources/assets/admin/entry.js';
```

## Extension points

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
"sylius-labs/coding-standard": "^3.0",
"symfony/debug-bundle": "^4.4 || ^5.4",
"symfony/dotenv": "^4.4 || ^5.4",
"symfony/web-profiler-bundle": "^4.4 || ^5.4"
"symfony/web-profiler-bundle": "^4.4 || ^5.4",
"symfony/webpack-encore-bundle": "^1.12",
"symfony/web-server-bundle": "^4.4 || ^5.4"
},
"conflict": {
"doctrine/dbal": "^3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
@admin_order_creation_managing_orders
Feature: Creating order with different billing address
In order to place an order in the name of a Customer
As an Administrator
I want to be able to create an order with different shipping and billing addresses in Admin panel

Background:
Given the store operates on a single channel in "United States"
And the store has a product "Stark Coat" priced at "$100"
And the store has a product "Lannister Banner" priced at "$40"
And the store ships everywhere for free
And the store allows paying with "Cash on Delivery"
And there is a customer account "[email protected]"
And their default address is "Ankh-Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And this customer has an address "Ned Stark", "Banana Street", "90232", "New York", "United States" in their address book
And I am logged in as an administrator

@ui @javascript
Scenario: Creating an order with both addresses from address books
When I create a new order for "[email protected]" and channel "United States"
And I add "Stark Coat" to this order
And I select first address in shipping address book with name "Jon Snow"
And I select first address in billing address book with name "Ned Stark"
And I select "Free" shipping method
And I select "Cash on Delivery" payment method
And I place and confirm this order
Then I should be notified that order has been successfully created
And this order shipping address should be "Jon Snow", "Frost Alley", "90210", "Ankh-Morpork", "United States"
And this order billing address should be "Ned Stark", "Banana Street", "90232", "New York", "United States"
And there should be one not paid nor shipped order with channel "United States" for "[email protected]" in the registry

@ui @javascript
Scenario: Creating an order with one address from address books
When I create a new order for "[email protected]" and channel "United States"
And I add "Stark Coat" to this order
And I specify this order shipping address as "Ankh-Morpork", "Frost Alley", "90210", "United States" for "Jon Snow"
And I select first address in billing address book with name "Ned Stark"
And I select "Free" shipping method
And I select "Cash on Delivery" payment method
And I place and confirm this order
Then I should be notified that order has been successfully created
And this order billing address should be "Ned Stark", "Banana Street", "90232", "New York", "United States"
And this order shipping address should be "Jon Snow", "Frost Alley", "90210", "Ankh-Morpork", "United States"
And there should be one not paid nor shipped order with channel "United States" for "[email protected]" in the registry
9 changes: 9 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@sylius/admin-order-creation-plugin",
"description": "Admin order creation plugin for Sylius.",
"repository": "https://github.com/Sylius/AdminOrderCreationPlugin.git",
"license": "MIT",
"scripts": {
"dist": "yarn encore production --config-name sylius-plugin-dist"
}
}
2 changes: 2 additions & 0 deletions src/Resources/assets/admin/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './scss/main.scss'
import './js'
64 changes: 64 additions & 0 deletions src/Resources/assets/admin/js/OrderCreateAddressSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const parseKey = function parseKey(key) {
return key.replace(/(_\w)/g, words => words[1].toUpperCase());
};

$.fn.extend({
addressBook() {
const element = this;
const select = element.parents('.js-address-container').prev().find('> *:first-child');

const findByName = function findByName(name) {
return element.find(`[name*="[${parseKey(name)}]"]`);
};

select.dropdown({
forceSelection: false,

onChange(name, text, choice) {
const { provinceCode, provinceName } = choice.data();
const provinceContainer = select.parent().find('.province-container').get(0);

element.find('input:not([type="radio"]):not([type="checkbox"]), select').each((index, input) => {
$(input).val('');
});

Object.entries(choice.data()).forEach(([property, value]) => {
const field = findByName(property);

if (property.indexOf('countryCode') !== -1) {
field.val(value).change();

const exists = setInterval(() => {
const provinceCodeField = findByName('provinceCode');
const provinceNameField = findByName('provinceName');

const provinceIsLoading = $(provinceContainer).attr('data-loading');

if (!(typeof provinceIsLoading !== 'undefinded' && provinceIsLoading !== false)) {
if (provinceCodeField.length !== 0 && (provinceCode !== '' || provinceCode != undefined)) {
provinceCodeField.val(provinceCode);

clearInterval(exists);
} else if (provinceNameField.length !== 0 && (provinceName !== '' || provinceName != undefined)) {
provinceNameField.val(provinceName);

clearInterval(exists);
}
}
}, 100);
} else if (field.is('[type="radio"]') || field.is('[type="checkbox"]')) {
field.prop('checked', false);
field.filter(`[value="${value}"]`).prop('checked', true);
} else {
field.val(value);
}
});
},
});
},
});

export default () => {
$('#sylius_admin_order_creation_new_order_shippingAddress').addressBook();
$('#sylius_admin_order_creation_new_order_billingAddress').addressBook();
};
5 changes: 5 additions & 0 deletions src/Resources/assets/admin/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import OrderCreateAddressSelect from './OrderCreateAddressSelect';

$(function() {
OrderCreateAddressSelect();
});
1 change: 1 addition & 0 deletions src/Resources/assets/admin/scss/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './pages/main';
1 change: 1 addition & 0 deletions src/Resources/assets/admin/scss/pages/main.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './order-creation/main';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.custom-address-select {
margin-bottom: 16px;
}
.custom-address-select .dropdown,
.custom-address-select .ui.search.dropdown > input.search {
cursor: pointer;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import './addressSelect';
2 changes: 2 additions & 0 deletions src/Resources/assets/shop/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './scss/main.scss'
import './js'
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ sylius_mailer:
order_created_in_admin_panel:
subject: 'sylius_admin_order_creation.email.order_created.subject'
template: '@SyliusAdminOrderCreationPlugin/Emails/orderCreated.html.twig'

sylius_ui:
events:
sylius.admin.layout.stylesheets:
blocks:
sylius_admin_order_creation:
template: '@SyliusAdminOrderCreationPlugin/Event/Admin/_styles.html.twig'
sylius.admin.layout.javascripts:
blocks:
sylius_admin_order_creation:
template: '@SyliusAdminOrderCreationPlugin/Event/Admin/_scripts.html.twig'
1 change: 1 addition & 0 deletions src/Resources/views/Event/Admin/_scripts.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ encore_entry_script_tags('sylius-order-creation-admin', null, 'admin') }}
1 change: 1 addition & 0 deletions src/Resources/views/Event/Admin/_styles.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ encore_entry_link_tags('sylius-order-creation-admin', null, 'admin') }}
23 changes: 23 additions & 0 deletions src/Resources/views/Order/Create/_addressBookSelect.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="ui fluid floating dropdown labeled search icon button address-book-select" {{ sylius_test_html_attribute('address-book') }}>
<i class="book icon"></i>
<span class="text">{{ 'sylius.ui.address_book'|trans }}</span>
<div class="menu">
{% for address in customer.addresses %}
<div class="item" {{ sylius_test_html_attribute('address-book-item') }}
data-id="{{ address.id }}"
data-first-name="{{ address.firstName }}"
data-last-name="{{ address.lastName }}"
data-company="{{ address.company }}"
data-street="{{ address.street }}"
data-country-code="{{ address.countryCode }}"
data-province-code="{{ address.provinceCode }}"
data-province-name="{{ address.provinceName }}"
data-city="{{ address.city }}"
data-postcode="{{ address.postcode }}"
data-phone-number="{{ address.phoneNumber }}"
>
<strong>{{ address.firstName }} {{ address.lastName }}</strong>, {{ address.street }}, {{ address.city }} {{ address.postcode }}, {{ address.countryCode|sylius_country_name }}
</div>
{% endfor %}
</div>
</div>
30 changes: 27 additions & 3 deletions src/Resources/views/Order/Create/_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,34 @@
<div class="title">
<i class="dropdown icon"></i> {{ 'sylius.ui.shipping_address'|trans }} &amp; {{ 'sylius.ui.billing_address'|trans }}
</div>
{% set customer = form.vars.value.customer %}
<div class="content">
<div class="ui horizontal segments">
<div class="ui segment">{{ form_row(form.shippingAddress) }}</div>
<div class="ui segment">{{ form_row(form.billingAddress) }}</div>
<div class="ui grid">
<div class="eight wide column">
<div class="ui segment">
{% if customer is not empty and customer.user is not empty and customer.addresses|length > 0 %}
<div class="custom-address-select js-address-select shipping-address-book">
{% include '@SyliusAdminOrderCreationPlugin/Order/Create/_addressBookSelect.html.twig' %}
</div>
{% endif %}
<div class="js-address-container">
{{ form_row(form.shippingAddress) }}
</div>
</div>
</div>

<div class="eight wide column">
<div class="ui segment">
{% if customer is not empty and customer.user is not empty and customer.addresses|length > 0 %}
<div class="custom-address-select js-address-select billing-address-book">
{% include '@SyliusAdminOrderCreationPlugin/Order/Create/_addressBookSelect.html.twig' %}
</div>
{% endif %}
<div class="js-address-container">
{{ form_row(form.billingAddress) }}
</div>
</div>
</div>
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions tests/Application/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/public/assets
/public/build
/public/css
/public/js
/public/media/*
Expand Down
1 change: 1 addition & 0 deletions tests/Application/assets/admin/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'sylius/bundle/AdminBundle/Resources/private/entry';
1 change: 1 addition & 0 deletions tests/Application/assets/shop/entry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'sylius/bundle/ShopBundle/Resources/private/entry';
3 changes: 3 additions & 0 deletions tests/Application/config/bundles.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Expand Down Expand Up @@ -56,4 +58,5 @@
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
SyliusLabs\Polyfill\Symfony\Security\Bundle\SyliusLabsPolyfillSymfonySecurityBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
];
11 changes: 11 additions & 0 deletions tests/Application/config/packages/assets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
framework:
assets:
packages:
shop:
json_manifest_path: '%kernel.project_dir%/public/build/shop/manifest.json'
admin:
json_manifest_path: '%kernel.project_dir%/public/build/admin/manifest.json'
orderCreation_shop:
json_manifest_path: '%kernel.project_dir%/public/build/sylius/orderCreation/shop/manifest.json'
orderCreation_admin:
json_manifest_path: '%kernel.project_dir%/public/build/sylius/orderCreation/admin/manifest.json'
Loading