Skip to content

Commit

Permalink
Merge pull request #70 from EaDesgin/feature/Romcity-moved-from-bitbu…
Browse files Browse the repository at this point in the history
…cket

Romcity:moved from Bitbucket
  • Loading branch information
mardeleanu authored Mar 4, 2020
2 parents acec74d + 48df0b8 commit 5e62357
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ public function getConfigFileName($nameFile = self::NAME_FILE)
return $this->getScopeConfig($nameFile);
}

}
}
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "eadesignro/romcity",
"description": "A module that adds checkout city field to checkout quote shipping address",
"type": "magento2-module",
"version": "1.1.7",
"version": "1.2.2",
"autoload": {
"files": [
"registration.php"
Expand All @@ -25,7 +25,7 @@
},

"require": {
"php": "~7.1.3||~7.2.0",
"php": "~7.1.3||~7.2.0|~7.3.0",
"magento/framework": "102.0.*",
"magento/module-backend": "101.0.*",
"magento/module-sales": "102.0.*",
Expand All @@ -43,4 +43,4 @@
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
4 changes: 2 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<label>Upload City</label>
<field id="city_file_upload" translate="label" type="Magento\Config\Block\System\Config\Form\Field\File"
sortOrder="6" showInDefault="1" showInWebsite="1">
<comment>To import cities, choose file and "Save Config". Then push the button "Import Cities!".</comment>
<comment>Create in pub/media a folder with name test. To import cities, choose file and "Save Config". Then push the button "Import Cities!".</comment>
<label>Browse import file </label>
<backend_model>Eadesigndev\RomCity\Model\Config\Backend\UploadFile</backend_model>
<upload_dir config="system" scope_info="0">test</upload_dir>
Expand All @@ -34,4 +34,4 @@
</group>
</section>
</system>
</config>
</config>
5 changes: 3 additions & 2 deletions etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Eadesigndev_RomCity" setup_version="1.1.7">
<module name="Eadesigndev_RomCity" setup_version="1.2.2">
<sequence>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
</config>
git c
16 changes: 2 additions & 14 deletions view/adminhtml/layout/sales_order_create_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,8 @@
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Sidebar\Pviewed" template="Magento_Sales::order/create/sidebar/items.phtml" name="pviewed"/>
</block>
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Form\Account" template="Magento_Sales::order/create/form/account.phtml" name="form_account"/>
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Address" template="Magento_Sales::order/create/form/address.phtml" name="shipping_address">
<arguments>
<argument name="customerAddressFormatter" xsi:type="object">Magento\Sales\ViewModel\Customer\AddressFormatter</argument>
<argument name="customerAddressCollection" xsi:type="object">Magento\Customer\Model\ResourceModel\Address\Collection</argument>
</arguments>
</block>
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address"
template="Eadesigndev_RomCity::order/create/form/address.phtml"
name="billing_address">
<arguments>
<argument name="customerAddressFormatter" xsi:type="object">Magento\Sales\ViewModel\Customer\AddressFormatter</argument>
<argument name="customerAddressCollection" xsi:type="object">Magento\Customer\Model\ResourceModel\Address\Collection</argument>
</arguments>
</block>
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Address" template="Magento_Sales::order/create/form/address.phtml" name="shipping_address"/>
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Billing\Address" template="Eadesigndev_RomCity::order/create/form/address.phtml" name="billing_address"/>
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method" template="Magento_Sales::order/create/abstract.phtml" name="shipping_method">
<block class="Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\Form" template="Magento_Sales::order/create/shipping/method/form.phtml" name="order_create_shipping_form" as="form"/>
</block>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Eadesigndev\RomCity\Block\Checkout\CityUpdater"
template="Eadesigndev_RomCity::order/create/form/address.phtml"
name="billing_address">
<arguments>
<argument name="customerAddressFormatter" xsi:type="object">Magento\Sales\ViewModel\Customer\AddressFormatter</argument>
<argument name="customerAddressCollection" xsi:type="object">Magento\Customer\Model\ResourceModel\Address\Collection</argument>
</arguments>
</block>
<block class="Eadesigndev\RomCity\Block\Checkout\CityUpdater" template="Eadesigndev_RomCity::order/create/form/address.phtml" name="billing_address"/>
</referenceContainer>
</body>
</page>
4 changes: 1 addition & 3 deletions view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
<item name="sortOrder" xsi:type="string">111</item>
</item>
<item name="city_id" xsi:type="array">


<item name="component" xsi:type="string">Eadesigndev_RomCity/js/form/element/city</item>
<item name="config" xsi:type="array">
<!--customScope is used to group elements within a single form (e.g. they can be validated separately)-->
Expand All @@ -92,7 +90,7 @@
<item name="value" xsi:type="string">value_2</item>
<item name="provider" xsi:type="string">checkoutProvider</item>
<item name="dataScope" xsi:type="string">customCheckoutForm.city_id</item>
<item name="label" xsi:type="string">City</item>
<item name="label" xsi:type="string">Localitate</item>
<item name="sortOrder" xsi:type="string">112</item>
</item>
</item>
Expand Down
6 changes: 6 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ var config = {
},
'Magento_Checkout/js/model/shipping-rate-processor/new-address': {
'Eadesigndev_RomCity/js/model/shipping-rate-processor/new-address': true
},
'Magento_Checkout/js/view/shipping-information/list':{
'Eadesigndev_RomCity/js/view/shipping-information/list-mixin' :true
},
'Magento_Checkout/js/view/payment/default':{
'Eadesigndev_RomCity/js/view/payment/default-mixin' :true
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions view/frontend/web/js/view/billing-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,28 @@ define(['jquery',

quote.billingAddress.subscribe(function (newAddress) {

var shippingCityId = $("#shipping-new-address-form [name = 'city_id'] option:selected"),
shippingCityIdValue = shippingCityId.text();
if(newAddress) {
let shippingCityId = $("#shipping-new-address-form [name = 'city_id'] option:selected"),
shippingCityIdValue = shippingCityId.text();
let billingAddressCity = $(".billing-address-form form [name='city_id'] option:selected");

newAddress.city = shippingCityIdValue;

if (this.isAddressSameAsShipping()) {
newAddress.city = shippingCityIdValue;
} else if (billingAddressCity) {
newAddress.city = billingAddressCity.text();
}
else{
newAddress.city = shippingCityIdValue;
}
if (localStorage.getItem('city_id') && !this.isAddressSameAsShipping()) {
newAddress.city = localStorage.getItem('city_id_value');
}
}
$(".billing-address-form form [name='city_id']").on('change',function () {
localStorage.setItem('city_id', $('option:selected',this).index());
localStorage.setItem('city_id_value', $('option:selected',this).text());
});

if (quote.isVirtual()) {
this.isAddressSameAsShipping(false);
Expand Down Expand Up @@ -110,6 +128,8 @@ define(['jquery',

if (!this.source.get('params.invalid')) {
addressData = this.source.get(this.dataScopePrefix);
let billingAddressCity = $(".billing-address-form form [name='city_id'] option:selected");
addressData.city = billingAddressCity.text();

if (customer.isLoggedIn() && !this.customerHasAddresses) { //eslint-disable-line max-depth
this.saveInAddressBook(1);
Expand All @@ -125,9 +145,6 @@ define(['jquery',
billingCityIdValue = billingCityId.text();
}
}

newBillingAddress.city = billingCityIdValue;

this.updateAddresses();
},
});
Expand Down
50 changes: 50 additions & 0 deletions view/frontend/web/js/view/payment/default-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'ko',
'jquery',
'uiComponent',
'Magento_Checkout/js/action/place-order',
'Magento_Checkout/js/action/select-payment-method',
'Magento_Checkout/js/model/quote',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/payment-service',
'Magento_Checkout/js/checkout-data',
'Magento_Checkout/js/model/checkout-data-resolver',
'uiRegistry',
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Ui/js/model/messages',
'uiLayout',
'Magento_Checkout/js/action/redirect-on-success'
], function (
ko,
$,
Component,
placeOrderAction,
selectPaymentMethodAction,
quote,
customer,
paymentService,
checkoutData,
checkoutDataResolver,
registry,
additionalValidators,
Messages,
layout,
redirectOnSuccessAction
) {
'use strict';

var mixin = {
afterPlaceOrder: function () {
localStorage.removeItem('city_id');
localStorage.removeItem('city_id_value');
}
};
return function (target) {
return target.extend(mixin);
}
});
39 changes: 39 additions & 0 deletions view/frontend/web/js/view/shipping-information/list-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'ko',
'mageUtils',
'uiComponent',
'uiLayout',
'Magento_Checkout/js/model/quote'
], function ($, ko, utils, Component, layout, quote) {
'use strict';

var mixin = {
initialize: function () {
var self = this;

this._super()
.initChildren();

quote.shippingAddress.subscribe(function (address) {
var shippingCityId = $("#shipping-new-address-form [name = 'city_id'] option:selected"),
shippingCityIdValue = shippingCityId.text();
if (shippingCityIdValue){
address.city = shippingCityIdValue;
}
self.createRendererComponent(address);
});

return this;
}
}
return function (target) {
return target.extend(mixin);
}

});

0 comments on commit 5e62357

Please sign in to comment.