diff --git a/src/CoreShop/Bundle/AddressBundle/Resources/config/pimcore/admin.yml b/src/CoreShop/Bundle/AddressBundle/Resources/config/pimcore/admin.yml index caf4cc7d68..a069566053 100644 --- a/src/CoreShop/Bundle/AddressBundle/Resources/config/pimcore/admin.yml +++ b/src/CoreShop/Bundle/AddressBundle/Resources/config/pimcore/admin.yml @@ -5,6 +5,7 @@ core_shop_address: resource_country: '/bundles/coreshopaddress/pimcore/js/resource/country.js' resource_state: '/bundles/coreshopaddress/pimcore/js/resource/state.js' resource_zone: '/bundles/coreshopaddress/pimcore/js/resource/zone.js' + resource_country_salutation: '/bundles/coreshopaddress/pimcore/js/resource/country_salutation.js' country_item: '/bundles/coreshopaddress/pimcore/js/country/item.js' country_panel: '/bundles/coreshopaddress/pimcore/js/country/panel.js' state_item: '/bundles/coreshopaddress/pimcore/js/state/item.js' @@ -24,4 +25,4 @@ core_shop_address: editmode_js: core_extension_document_tag_country: '/bundles/coreshopaddress/pimcore/js/coreExtension/document/coreShopCountry.js' core_extension_document_tag_state: '/bundles/coreshopaddress/pimcore/js/coreExtension/document/coreShopState.js' - core_extension_document_tag_zone: '/bundles/coreshopaddress/pimcore/js/coreExtension/document/coreShopZone.js' \ No newline at end of file + core_extension_document_tag_zone: '/bundles/coreshopaddress/pimcore/js/coreExtension/document/coreShopZone.js' diff --git a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country.js b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country.js index b1111859be..298cbec3b6 100644 --- a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country.js +++ b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country.js @@ -1,4 +1,4 @@ -Ext.define('CoreShop.store.Country', { +Ext.define('CoreShop.address.Country', { extend: 'CoreShop.resource.ComboBox', alias: 'widget.coreshop.country', diff --git a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country_salutation.js b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country_salutation.js new file mode 100644 index 0000000000..12526b431b --- /dev/null +++ b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/country_salutation.js @@ -0,0 +1,76 @@ +Ext.define('CoreShop.address.CountrySalutation', { + extend: 'Ext.container.Container', + alias: 'widget.coreshop.countrySalutation', + + config: { + country: { + name: 'country' + }, + salutation: { + name: 'salutation' + } + }, + + initComponent: function () { + this.items = [Ext.mergeIf(this.country, { + xtype: 'coreshop.country', + store: { + proxy: { + type: 'ajax', + url: '/admin/coreshop/countries/list-active', + reader: { + type: 'json', + } + }, + fields: [ + {name: 'id'}, + {name: 'name'} + ], + autoLoad: true, + remoteSort: false, + remoteFilter: false + }, + name: this.name_country, + allowBlank: false, + listeners: { + change: function(cmb) { + if (cmb.getValue() === null) { + cmb.up('panel').down('#salutation').setValue(null); + cmb.up('panel').down('#salutation').setDisabled(true); + } + else { + Ext.Ajax.request({ + url: '/admin/coreshop/countries/get', + method: 'get', + params: { + id: cmb.getValue() + }, + success: function (response) { + var res = Ext.decode(response.responseText); + + if (res.success) { + cmb.up('panel').down('#salutation').setStore(res.data.salutations.map(function(entry) { + return [entry, t('coreshop_salutation_' + entry)]; + })); + cmb.up('panel').down('#salutation').setDisabled(false); + } + }.bind(this) + }); + } + } + } + }), Ext.mergeIf(this.salutation, { + xtype: 'combo', + fieldLabel: t('coreshop_country_salutation'), + itemId: 'salutation', + name: this.name_salutation, + disabled: true, + allowBlank: false, + queryMode: 'local', + editable: false, + store: [] + })]; + + this.callParent(); + } +}); diff --git a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/state.js b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/state.js index 0776ea77f8..010f39a797 100644 --- a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/state.js +++ b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/state.js @@ -1,4 +1,4 @@ -Ext.define('CoreShop.store.State', { +Ext.define('CoreShop.address.State', { extend: 'CoreShop.resource.ComboBox', alias: 'widget.coreshop.state', diff --git a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/zone.js b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/zone.js index d9eaed81a3..3235946af9 100644 --- a/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/zone.js +++ b/src/CoreShop/Bundle/AddressBundle/Resources/public/pimcore/js/resource/zone.js @@ -1,4 +1,4 @@ -Ext.define('CoreShop.store.Zone', { +Ext.define('CoreShop.address.Zone', { extend: 'CoreShop.resource.ComboBox', alias: 'widget.coreshop.zone', diff --git a/src/CoreShop/Bundle/CurrencyBundle/Resources/public/pimcore/js/resource/currency.js b/src/CoreShop/Bundle/CurrencyBundle/Resources/public/pimcore/js/resource/currency.js index 32bfdbc21c..ae939e5306 100644 --- a/src/CoreShop/Bundle/CurrencyBundle/Resources/public/pimcore/js/resource/currency.js +++ b/src/CoreShop/Bundle/CurrencyBundle/Resources/public/pimcore/js/resource/currency.js @@ -1,4 +1,4 @@ -Ext.define('CoreShop.store.Currency', { +Ext.define('CoreShop.currency.Currency', { extend: 'CoreShop.resource.ComboBox', alias: 'widget.coreshop.currency', diff --git a/src/CoreShop/Bundle/CustomerBundle/Form/Type/CustomerType.php b/src/CoreShop/Bundle/CustomerBundle/Form/Type/CustomerType.php index 455ff7531f..91aef6f744 100644 --- a/src/CoreShop/Bundle/CustomerBundle/Form/Type/CustomerType.php +++ b/src/CoreShop/Bundle/CustomerBundle/Form/Type/CustomerType.php @@ -56,6 +56,18 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'label' => 'coreshop.form.customer.lastname', ]); + if ($options['use_repeat_email']) { + $builder + ->add('email', RepeatedType::class, [ + 'type' => EmailType::class, + 'invalid_message' => 'coreshop.form.customer.email.must_match', + 'first_options' => ['label' => 'coreshop.form.customer.email'], + 'second_options' => ['label' => 'coreshop.form.customer.email_repeat'], + + ]); + } else { + $builder->add('email', EmailType::class); + } if ($options['allow_username']) { $builder->add('username', TextType::class, [ @@ -63,13 +75,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]); } - $builder->add('email', RepeatedType::class, [ - 'type' => EmailType::class, - 'invalid_message' => 'coreshop.form.customer.email.must_match', - 'first_options' => ['label' => 'coreshop.form.customer.email'], - 'second_options' => ['label' => 'coreshop.form.customer.email_repeat'], - ]); - if (!$options['guest'] && $options['allow_password_field']) { $builder ->add('password', RepeatedType::class, [ @@ -96,6 +101,7 @@ public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); + $resolver->setDefault('use_repeat_email', true); $resolver->setDefault('guest', false); $resolver->setDefault('allow_password_field', false); $resolver->setDefault('allow_username', false); diff --git a/src/CoreShop/Bundle/OrderBundle/Controller/AddressCreationController.php b/src/CoreShop/Bundle/OrderBundle/Controller/AddressCreationController.php new file mode 100644 index 0000000000..97c314ae71 --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Controller/AddressCreationController.php @@ -0,0 +1,86 @@ +get('form.factory')->createNamed('', AdminAddressCreationType::class); + + if ($request->getMethod() === 'POST') { + $form = $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $data = $form->getData(); + + /** + * @var CustomerInterface $customer + */ + $customer = $data['customer']; + + /** + * @var AddressInterface $address + */ + $address = $data['address']; + + $address->setPublished(true); + $address->setKey(uniqid()); + $address->setParent($objectService->createFolderByPath(sprintf( + '/%s/%s', + $customer->getFullPath(), + $this->getParameter('coreshop.folder.address') + ))); + $address->save(); + + if ($customer instanceof AddressesAwareInterface) { + $customer->addAddress($address); + } + + $this->get('event_dispatcher')->dispatch( + Events::ADMIN_ADDRESS_CREATION, + new AdminAddressCreationEvent($address, $customer, $data) + ); + + $customer->save(); + + return $this->viewHandler->handle(['success' => true, 'id' => $address->getId()]); + } + + return $this->viewHandler->handle( + [ + 'success' => false, + 'message' => $errorSerializer->serializeErrorFromHandledForm($form), + ] + ); + } + + return $this->viewHandler->handle(['success' => false, 'message' => 'Method not supported, use POST']); + } +} diff --git a/src/CoreShop/Bundle/OrderBundle/Controller/CustomerCreationController.php b/src/CoreShop/Bundle/OrderBundle/Controller/CustomerCreationController.php new file mode 100644 index 0000000000..1ea87f598c --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Controller/CustomerCreationController.php @@ -0,0 +1,103 @@ +get('form.factory')->createNamed('', AdminCustomerCreationType::class); + + if ($request->getMethod() === 'POST') { + $form = $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $data = $form->getData(); + + /** + * @var CustomerInterface $customer + */ + $customer = $data['customer']; + + /** + * @var AddressInterface $address + */ + $address = $data['address']; + + $customer->setPublished(true); + $customer->setParent($objectService->createFolderByPath(sprintf( + '/%s/%s', + $this->getParameter('coreshop.folder.customer'), + mb_strtoupper(mb_substr($customer->getLastname(), 0, 1)) + ))); + $customer->setKey(File::getValidFilename($customer->getEmail())); + $customer->setKey(Service::getUniqueKey($customer)); + $customer->save(); + + $address->setPublished(true); + $address->setKey(uniqid()); + $address->setParent($objectService->createFolderByPath(sprintf( + '/%s/%s', + $customer->getFullPath(), + $this->getParameter('coreshop.folder.address') + ))); + $address->save(); + + if ($customer instanceof DefaultAddressAwareInterface) { + $customer->setDefaultAddress($address); + } + + if ($customer instanceof AddressesAwareInterface) { + $customer->addAddress($address); + } + + $this->get('event_dispatcher')->dispatch( + Events::ADMIN_CUSTOMER_CREATION, + new AdminCustomerCreationEvent($customer, $data) + ); + + $customer->save(); + + return $this->viewHandler->handle(['success' => true, 'id' => $customer->getId()]); + } + + return $this->viewHandler->handle( + [ + 'success' => false, + 'message' => $errorSerializer->serializeErrorFromHandledForm($form), + ] + ); + } + + return $this->viewHandler->handle(['success' => false, 'message' => 'Method not supported, use POST']); + } +} diff --git a/src/CoreShop/Bundle/OrderBundle/Controller/OrderCreationController.php b/src/CoreShop/Bundle/OrderBundle/Controller/OrderCreationController.php index 395f17019d..838fce8453 100644 --- a/src/CoreShop/Bundle/OrderBundle/Controller/OrderCreationController.php +++ b/src/CoreShop/Bundle/OrderBundle/Controller/OrderCreationController.php @@ -263,7 +263,7 @@ protected function getCurrency(CurrencyInterface $currency): array return [ 'name' => $currency->getName(), 'symbol' => $currency->getSymbol(), - 'uso' => $currency->getIsoCode() + 'iso' => $currency->getIsoCode() ]; } diff --git a/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php b/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php index bf67929cef..69a0c845ce 100644 --- a/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php +++ b/src/CoreShop/Bundle/OrderBundle/DependencyInjection/Configuration.php @@ -14,7 +14,9 @@ namespace CoreShop\Bundle\OrderBundle\DependencyInjection; +use CoreShop\Bundle\OrderBundle\Controller\AddressCreationController; use CoreShop\Bundle\OrderBundle\Controller\CartPriceRuleController; +use CoreShop\Bundle\OrderBundle\Controller\CustomerCreationController; use CoreShop\Bundle\OrderBundle\Controller\OrderCommentController; use CoreShop\Bundle\OrderBundle\Controller\OrderController; use CoreShop\Bundle\OrderBundle\Controller\OrderCreationController; @@ -213,6 +215,8 @@ private function addModelsSection(ArrayNodeDefinition $node) ->scalarNode('edit')->defaultValue(OrderEditController::class)->end() ->scalarNode('payment')->defaultValue(OrderPaymentController::class)->end() ->scalarNode('comment')->defaultValue(OrderCommentController::class)->end() + ->scalarNode('customer_creation')->defaultValue(CustomerCreationController::class)->end() + ->scalarNode('address_creation')->defaultValue(AddressCreationController::class)->end() ->end() ->end() ->end() diff --git a/src/CoreShop/Bundle/OrderBundle/Event/AdminAddressCreationEvent.php b/src/CoreShop/Bundle/OrderBundle/Event/AdminAddressCreationEvent.php new file mode 100644 index 0000000000..d72c5389e5 --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Event/AdminAddressCreationEvent.php @@ -0,0 +1,66 @@ +address = $address; + $this->customer = $customer; + $this->data = $data; + } + + /** + * @return AddressInterface + */ + public function getAddress() + { + return $this->address; + } + + /** + * @return CustomerInterface + */ + public function getCustomer() + { + return $this->customer; + } + + /** + * @return array + */ + public function getData() + { + return $this->data; + } +} diff --git a/src/CoreShop/Bundle/OrderBundle/Event/AdminCustomerCreationEvent.php b/src/CoreShop/Bundle/OrderBundle/Event/AdminCustomerCreationEvent.php new file mode 100644 index 0000000000..812d2e5a65 --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Event/AdminCustomerCreationEvent.php @@ -0,0 +1,51 @@ +customer = $customer; + $this->data = $data; + } + + /** + * @return CustomerInterface + */ + public function getCustomer() + { + return $this->customer; + } + + /** + * @return array + */ + public function getData() + { + return $this->data; + } +} diff --git a/src/CoreShop/Bundle/OrderBundle/Events.php b/src/CoreShop/Bundle/OrderBundle/Events.php index 3773c22dba..4389dc94b8 100644 --- a/src/CoreShop/Bundle/OrderBundle/Events.php +++ b/src/CoreShop/Bundle/OrderBundle/Events.php @@ -20,4 +20,14 @@ final class Events * Fired before a Sale (Cart, Order, Quote) is passed to the client */ const SALE_DETAIL_PREPARE = 'coreshop.sale.detail.prepare'; + + /** + * Fired when an Admin creates a new Customer via a CoreShop UI + */ + const ADMIN_CUSTOMER_CREATION = 'coreshop.customer.admin_creation'; + + /** + * Fired when an Admin creates a new Address via a CoreShop UI + */ + const ADMIN_ADDRESS_CREATION = 'coreshop.address.admin_creation'; } diff --git a/src/CoreShop/Bundle/OrderBundle/Form/Type/AdminAddressCreationType.php b/src/CoreShop/Bundle/OrderBundle/Form/Type/AdminAddressCreationType.php new file mode 100644 index 0000000000..66fe0538df --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Form/Type/AdminAddressCreationType.php @@ -0,0 +1,49 @@ +add('customer', CustomerSelectionType::class, [ + 'constraints' => [ + new NotBlank(['groups' => ['coreshop']]), + ], + ]) + ->add('address', AddressType::class, [ + 'constraints' => [ + new Valid(['groups' => ['coreshop']]), + ], + ]); + } + + public function configureOptions(OptionsResolver $resolver) + { + parent::configureOptions($resolver); + + $resolver->setDefaults([ + 'csrf_protection' => false, + ]); + } +} diff --git a/src/CoreShop/Bundle/OrderBundle/Form/Type/AdminCustomerCreationType.php b/src/CoreShop/Bundle/OrderBundle/Form/Type/AdminCustomerCreationType.php new file mode 100644 index 0000000000..6373c54812 --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Form/Type/AdminCustomerCreationType.php @@ -0,0 +1,51 @@ +add('customer', CustomerType::class, [ + 'allow_password_field' => false, + 'use_repeat_email' => false, + 'guest' => true, + 'constraints' => [ + new Valid(['groups' => ['coreshop']]), + ], + ]) + ->add('address', AddressType::class, [ + 'constraints' => [ + new Valid(['groups' => ['coreshop']]), + ], + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + parent::configureOptions($resolver); + + $resolver->setDefaults([ + 'csrf_protection' => false + ]); + } +} diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/admin.yml b/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/admin.yml index 52c22e06c5..338d334af5 100644 --- a/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/admin.yml +++ b/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/admin.yml @@ -23,6 +23,8 @@ core_shop_order: # sale_detail_abstract_block_detail: '/bundles/coreshoporder/pimcore/js/sale/detail/blocks/detail.js' # sale_list: '/bundles/coreshoporder/pimcore/js/sale/list.js' # sale_creation_panel: '/bundles/coreshoporder/pimcore/js/sale/create/panel.js' + order_creation_customer: '/bundles/coreshoporder/pimcore/js/order/create/customer.js' + order_creation_address: '/bundles/coreshoporder/pimcore/js/order/create/address.js' order_detail_abstract_block: '/bundles/coreshoporder/pimcore/js/order/detail/abstractBlock.js' order_creation_abstract_step: '/bundles/coreshoporder/pimcore/js/order/create/abstractStep.js' order_creation_step_base: '/bundles/coreshoporder/pimcore/js/order/create/step/base.js' diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/routing.yml b/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/routing.yml index 18a88c4b0a..3385a698f8 100755 --- a/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/routing.yml +++ b/src/CoreShop/Bundle/OrderBundle/Resources/config/pimcore/routing.yml @@ -141,3 +141,12 @@ coreshop_admin_order_add: coreshop_admin_order_remove: path: /%coreshop.admin.route.base%/order-edit/remove-item defaults: { _controller: 'coreshop.pimcore_controller.order_edit:removeItemAction'} + +##### CUSTOMER CREATION +coreshop_admin_order_customer_creation: + path: /%coreshop.admin.route.base%/order/customer/create + defaults: { _controller: 'coreshop.pimcore_controller.order_customer_creation:createCustomerAction'} + +coreshop_admin_order_address_creation: + path: /%coreshop.admin.route.base%/order/address/create + defaults: { _controller: 'coreshop.pimcore_controller.order_address_creation:createAddressAction'} diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/address.js b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/address.js new file mode 100644 index 0000000000..5f00cf9cda --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/address.js @@ -0,0 +1,74 @@ +/* + * CoreShop. + * + * This source file is subject to the GNU General Public License version 3 (GPLv3) + * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt + * files that are distributed with this source code. + * + * @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) + * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) + * + */ + +pimcore.registerNS('coreshop.order.order.create.address'); +coreshop.order.order.create.address = Class.create(coreshop.resource.creation, { + url: '/admin/coreshop/order/address/create', + type: 'address', + + getSettings: function() { + return [this.getAddressSettings()]; + }, + + getAddressSettings: function () { + this.addressForm = Ext.create('Ext.form.FieldSet', { + title: t('coreshop_address_create'), + items: [{ + xtype: 'coreshop.countrySalutation', + country: { + name: this.options.prefix + 'country', + fieldLabel: t('coreshop_address_create_country'), + }, + salutation: { + name: this.options.prefix + 'salutation', + fieldLabel: t('coreshop_address_create_salutation'), + }, + }, { + xtype: 'textfield', + name: this.options.prefix + 'firstname', + fieldLabel: t('coreshop_address_create_firstname'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'lastname', + fieldLabel: t('coreshop_address_create_lastname'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'street', + fieldLabel: t('coreshop_address_create_street'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'number', + fieldLabel: t('coreshop_address_create_number'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'postcode', + fieldLabel: t('coreshop_address_create_postcode'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'city', + fieldLabel: t('coreshop_address_create_city'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'phoneNumber', + fieldLabel: t('coreshop_address_create_phone_number') + }] + }); + + return this.addressForm; + }, +}); diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/customer.js b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/customer.js new file mode 100644 index 0000000000..13f0b67adc --- /dev/null +++ b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/customer.js @@ -0,0 +1,59 @@ +/* + * CoreShop. + * + * This source file is subject to the GNU General Public License version 3 (GPLv3) + * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt + * files that are distributed with this source code. + * + * @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) + * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) + * + */ + +pimcore.registerNS('coreshop.order.order.create.customer'); +coreshop.order.order.create.customer = Class.create(coreshop.resource.creation, { + url: '/admin/coreshop/order/customer/create', + type: 'customer', + + getSettings: function() { + return [ + this.getCustomerSettings(), + this.getAddressSettings() + ]; + }, + + getCustomerSettings: function () { + this.customerForm = Ext.create('Ext.form.FieldSet', { + title: t('coreshop_customer_create_customer'), + items: [{ + xtype: 'combobox', + store: [['male', t('coreshop_gender_male')], ['female', t('coreshop_gender_female')]], + name: this.options.prefix + 'gender', + fieldLabel: t('coreshop_customer_create_gender'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'firstname', + fieldLabel: t('coreshop_customer_create_firstname'), + allowBlank: false + }, { + xtype: 'textfield', + name: this.options.prefix + 'lastname', + fieldLabel: t('coreshop_customer_create_lastname'), + allowBlank: false + }, { + xtype: 'textfield', + vtype: 'email', + name: this.options.prefix + 'email', + fieldLabel: t('coreshop_customer_create_email'), + allowBlank: false + }] + }); + + return this.customerForm; + }, + + getAddressSettings: function () { + return new coreshop.order.order.create.address({prefix: 'address.'}).getAddressSettings(); + }, +}); diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/panel.js b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/panel.js index 2823548c57..b921fbe860 100644 --- a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/panel.js +++ b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/panel.js @@ -66,25 +66,38 @@ coreshop.order.order.create.panel = Class.create({ }, loadSaleRelator: function() { - var me = this; + var me = this, + toolbarConfig = []; + + toolbarConfig.push(new Ext.Button({ + text: t("coreshop_order_create_customer"), + handler: this.createRelator.bind(this), + iconCls: "pimcore_icon_add", + enableToggle: true + })); - pimcore.helpers.itemselector( + this.selector = new coreshop.selector.selector( false, function (customer) { - this.loadCustomerDetail(customer.id); - }.bind(me), + me.loadCustomerDetail(customer.id); + }, { - type: ['object'], - subtype: { - object: ['object'] - }, - specific: { - classes: coreshop.stack.coreshop.customer - } + classes: coreshop.stack.coreshop.customer + }, + { + toolbar: toolbarConfig } ); }, + createRelator: function() { + var me = this; + new coreshop.order.order.create.customer({prefix: 'customer.'}, function(id) { + me.selector.window.close(); + me.loadCustomerDetail(id); + }).show(); + }, + loadCustomerDetail: function (customerId) { this.customerId = customerId; diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/step/address.js b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/step/address.js index 4d2d741972..3335b453c3 100644 --- a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/step/address.js +++ b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/order/create/step/address.js @@ -43,7 +43,7 @@ coreshop.order.order.create.step.address = Class.create(coreshop.order.order.cre }, setPreviewData: function(data) { - + this.addressStore.setData(data.customer.addresses); }, getValues: function (parent) { @@ -87,6 +87,7 @@ coreshop.order.order.create.step.address = Class.create(coreshop.order.order.cre xtype: 'combo', fieldLabel: t('coreshop_address_' + type), labelWidth: 150, + itemId: 'address', name: type + 'Address', store: this.addressStore, editable: false, @@ -115,6 +116,25 @@ coreshop.order.order.create.step.address = Class.create(coreshop.order.order.cre }.bind(this) } }, + { + xtype: 'button', + iconCls: 'pimcore_icon_add', + text: t('coreshop_address_create'), + handler: function () { + new coreshop.order.order.create.address( + { + prefix: 'address.', + params: { + customer: this.creationPanel.customerId + } + }, function(id) { + this[key].down('#address').setValue(id); + + this.eventManager.fireEvent('preview'); + }.bind(this) + ).show(); + }.bind(this) + }, this[addressDetailPanelKey] ] }); diff --git a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/sale/detail/blocks/detail.js b/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/sale/detail/blocks/detail.js deleted file mode 100644 index abcc7846b3..0000000000 --- a/src/CoreShop/Bundle/OrderBundle/Resources/public/pimcore/js/sale/detail/blocks/detail.js +++ /dev/null @@ -1,295 +0,0 @@ -/* - * CoreShop. - * - * This source file is subject to the GNU General Public License version 3 (GPLv3) - * For the full copyright and license information, please view the LICENSE.md and gpl-3.0.txt - * files that are distributed with this source code. - * - * @copyright Copyright (c) 2015-2020 Dominik Pfaffenbauer (https://www.pfaffenbauer.at) - * @license https://www.coreshop.org/license GNU General Public License version 3 (GPLv3) - * - */ - -pimcore.registerNS('coreshop.order.sale.detail.blocks.detail'); -coreshop.order.sale.detail.blocks.detail = Class.create(coreshop.order.sale.detail.abstractBlock, { - - initBlock: function () { - - this.detailsStore = new Ext.data.JsonStore({ - data: [] - }); - - this.summaryStore = new Ext.data.JsonStore({ - data: [] - }); - - this.detailsInfo = Ext.create('Ext.panel.Panel', { - title: t('coreshop_products'), - border: true, - margin: '0 0 20 0', - iconCls: 'coreshop_icon_product', - }); - }, - - getPriority: function () { - return 10; - }, - - getPosition: function () { - return 'bottom'; - }, - - getPanel: function () { - return this.detailsInfo; - }, - - updateSale: function () { - - var detailItems; - - this.detailsStore.loadRawData(this.sale.details); - this.summaryStore.loadRawData(this.sale.summary); - - this.detailsInfo.removeAll(); - - detailItems = [this.generateItemGrid(), this.generateSummaryGrid()]; - - if (this.sale.priceRule) { - detailItems.splice(1, 0, this.generatePriceRuleItem(this.sale.priceRule)); - } - - this.detailsInfo.add(detailItems); - }, - - generateItemGrid: function () { - - var _ = this, - hasAdditionalData = false; - - if (Ext.isArray(this.sale.details)) { - Ext.Array.each(this.sale.details, function (row) { - if (row.hasOwnProperty('additional_details')) { - hasAdditionalData = true; - return false; - } - }) - } - - return { - xtype: 'grid', - margin: '0 0 15 0', - cls: 'coreshop-detail-grid', - store: this.detailsStore, - listeners: { - viewready: function (grid) { - if (hasAdditionalData === true) { - var view = grid.getView(), - rowExpander = grid.findPlugin('rowexpander'), - store = grid.getStore(), item; - for (var i = 0; i <= store.getCount(); i++) { - item = store.getAt(i); - if (item) { - rowExpander.toggleRow(i, item); - } - } - // remove toggle icon - view.getHeaderAtIndex(0).hide(); - } - } - }, - plugins: hasAdditionalData === true ? [{ - ptype: 'rowexpander', - expandOnDblClick: false, - rowBodyTpl: new Ext.XTemplate( - '
', - '{[ this.formatData(values) ]}', - ' | ', - '