Skip to content
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

Feature/11 #109

Open
wants to merge 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
901bdde
Add object variables in global scope with snowdog naming
Dec 7, 2018
abee95f
Simplify access to variables in store
Dec 7, 2018
610e757
WIP - Add i18n module with testing translations and start with adding it
Dec 7, 2018
62a422d
Add locale variable to tell our module which lang to use and translate
Dec 10, 2018
6ddde13
Add translation function in all possibly places + add translation JSO…
Dec 10, 2018
8d0b234
Add i18n module in tests and update snapshot
Dec 10, 2018
8adfe59
Merge remote-tracking branch 'composer/develop' into feature/11
Dec 11, 2018
1858e64
Merge remote-tracking branch 'composer/develop' into feature/11
Dec 21, 2018
854d498
Update config variables in index store
Dec 21, 2018
3fa338d
Update storeLocale to set default lang
Dec 21, 2018
42d4525
WIP adding HMR to use dynamic imports and load only necessary languages
Dec 21, 2018
2488a91
Revert HMR at this point
Dec 30, 2018
0555292
Split languages to separate files as langs and adjust script to selec…
Dec 30, 2018
3164d9b
Use global variable in utils
Dec 30, 2018
a639c2c
Create flat translations object to use slugs in templates
Dec 30, 2018
aca0803
Fix one translation in product list item
Dec 30, 2018
4856c54
Add global variable in jest configuration in package.json
Dec 30, 2018
796e567
Revert unecessary changes from HMR b/c we don't use it
Jan 4, 2019
708739f
Simplify array of translations and name of function to update lang
Jan 4, 2019
26ad44a
Merge remote-tracking branch 'composer/develop' into feature/11
Jan 4, 2019
829f291
Remove repetaed non translated text
Jan 4, 2019
230a1fb
Repair formatting in vue file
Jan 4, 2019
6bdf62c
Update translations and remove ':' sign with adding it in templates
Jan 4, 2019
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
1 change: 1 addition & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"plugins": ["syntax-dynamic-import"],
kjugi marked this conversation as resolved.
Show resolved Hide resolved
"presets": [
["env", { "modules": false }],
"stage-3"
Expand Down
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = {
root: true,
parserOptions: {
sourceType: 'module'
parser: "babel-eslint",
ecmaVersion: 8,
sourceType: "module"
},
env: {
browser: true,
Expand Down
11 changes: 10 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,36 @@
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/jest-vue-preprocessor"
},
"globals": {
"snowdog": {
"baseUrl": "global-base-url"
}
}
},
"dependencies": {
"axios": "^0.18.0",
"vue": "^2.4.4",
"vue-i18n": "^8.4.0",
"vue-multiselect": "^2.1.0",
"vuelidate": "^0.7.4",
"vuex": "^3.0.0"
},
"devDependencies": {
"@vue/test-utils": "^1.0.0-beta.20",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-jest": "^23.0.1",
"babel-loader": "^7.1.4",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-3": "^6.24.1",
"css-loader": "^0.28.7",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-import": "^2.10.0",
"eslint-plugin-import": "^2.13.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.7.0",
"eslint-plugin-standard": "^3.0.1",
Expand Down
16 changes: 13 additions & 3 deletions test/ProductsList.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import Vuei18n from 'vue-i18n'
import { mount, createLocalVue } from '@vue/test-utils'
import messages from '../view/frontend/web/js/data/translations-en_US.json'
import ProductsList from '../view/frontend/web/js/components/ProductsList.vue'

const localVue = createLocalVue()
localVue.use(Vuei18n)
const i18n = new Vuei18n({
locale: 'en_US',
messages
})

Vue.filter('currency', function (price) {
const pattern = '$%s'
price = parseFloat(price).toFixed(2)
return pattern.replace('%s', price)
})

describe('ProductsList.test.js', () => {

let wrapper

beforeEach(() => {
Expand Down Expand Up @@ -41,7 +49,9 @@ describe('ProductsList.test.js', () => {
}
],
step: () => 'shipping'
}
},
localVue,
i18n
})
})

Expand Down
1 change: 1 addition & 0 deletions test/__snapshots__/ProductsList.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ exports[`ProductsList.test.js has the expected html structure 1`] = `
>

Price:


<strong>

Expand Down
12 changes: 10 additions & 2 deletions view/frontend/templates/onepage.phtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$store = $objectManager->get('Magento\Framework\Locale\Resolver');
?>

<div id="checkout" class="checkout-container"></div>

<script>
var config = <?= \Zend_Json::encode($block->getCheckoutConfig()) ?>;
var baseUrl = '<?= $block->getBaseUrl() ?>';
var snowdog = snowdog ? snowdog : {};

snowdog.config = <?= \Zend_Json::encode($block->getCheckoutConfig()) ?>;
snowdog.baseUrl = '<?= $block->getBaseUrl() ?>';
snowdog.storeLocale = '<?= $store->getLocale() ?>';
kjugi marked this conversation as resolved.
Show resolved Hide resolved
</script>

<script type="text/x-magento-init">
Expand Down
32 changes: 16 additions & 16 deletions view/frontend/web/js/components/BillingAddressForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,78 +3,78 @@
<BaseInput
v-model="$v.address.firstname.$model"
:validation="$v.address.firstname"
label="First name"
:label="$t('First Name')"
name="firstname"
/>
<BaseInput
v-model="$v.address.lastname.$model"
:validation="$v.address.lastname"
label="Last name"
:label="$t('Last Name')"
name="lastname"
/>
<BaseInput
v-model="$v.address.telephone.$model"
:validation="$v.address.telephone"
label="Phone Number"
:label="$t('Phone Number')"
name="telephone"
type="tel"
/>
<BaseInput
v-model="$v.address.street0.$model"
:validation="$v.address.street0"
label="Street Address"
:label="$t('Street Address')"
name="street0"
/>
<BaseInput
v-model="address.street1"
label="Street Address"
:label="$t('Street Address')"
name="street1"
/>
<div>
<label for="country">
Select Country
{{ $t('Select Country') }}
</label>
<multiselect
id="country"
v-model="$v.address.country_id.$model"
:options="countries"
:allow-empty="false"
:show-labels="false"
:placeholder="$t('Select Country')"
name="country"
label="label"
placeholder="Select country"
/>
<span
v-if="
$v.address.country_id.$error
&& !$v.address.country_id.required
"
>
This field is required!
{{ $t('This field is required!') }}
</span>
</div>
<BaseInput
v-model="$v.address.city.$model"
:validation="$v.address.city"
label="City"
:label="$t('City')"
name="city"
/>
<BaseInput
v-model="$v.address.postcode.$model"
:validation="$v.address.postcode"
label="Zip/Postal Code"
:label="$t('Zip Code')"
name="postcode"
/>
<BaseInput
v-if="!regions.length"
v-model="$v.address.region.$model"
:validation="$v.address.region"
label="State/Province"
:label="$t('State')"
name="region"
/>
<div v-if="regions.length">
<label for="region_id">
Select State/Province
{{ $t('Select State') }}
</label>
<multiselect
id="region_id"
Expand All @@ -83,26 +83,26 @@
:options="regions"
:allow-empty="false"
:show-labels="false"
:placeholder="$t('State')"
name="region_id"
label="label"
placeholder="Select State/Province"
/>
<span
v-if="
$v.address.region_id.$error
&& !$v.address.region_id.required
"
>
This field is required!
{{ $t('This field is required!') }}
</span>
</div>
<BaseInput
v-model="address.company"
label="Company"
:label="$t('Company')"
name="company"
/>
<BaseButton
text="Save Address"
:text="$t('Save Address')"
@click.native="saveAddress"
/>
</form>
Expand Down
7 changes: 2 additions & 5 deletions view/frontend/web/js/components/CustomerEmailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,9 @@ export default {
emailAvailabilityMessage () {
if (this.email !== '' && !this.$v.email.$error) {
if (this.emailAvailable) {
return `You can create an account after checkout.`
return this.$t('You can create an account after checkout')
} else {
return `
You already have an account with us.
Sign in <a href="/customer/account/login/">here</a> or continue as guest.
`
return this.$t('You already have an account with us', { link: '/customer/account/login/' })
}
} else {
return false
Expand Down
16 changes: 8 additions & 8 deletions view/frontend/web/js/components/DiscountCodeForm.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
<template>
<div>
<h2>
Discount
{{ $t('Discount') }}
</h2>
<div class="discount-code">
<form class="discount__form">
<BaseInput
v-model="discount.code"
:read-only="couponCode !== ''"
label="Apply Discount Code"
:label="$t('Apply Discount Code')"
name="discount-code"
/>
<BaseButton
v-if="couponCode === ''"
:loader="loader"
:text="$t('Apply Discount')"
class="button"
text="Apply Discount"
with-loader
@click.native="applyDiscount"
/>
<BaseButton
v-else
:loader="loader"
:text="$t('Remove Discount')"
class="button"
text="Remove Discount"
@click.native="removeDiscount"
/>
<p
Expand Down Expand Up @@ -82,9 +82,9 @@ export default {
this.loader = false

if (error.status === 404) {
this.error = `Coupon code not found! Failed when trying to activate: '${this.discount.code}' coupon code. Please use another one.`
this.error = this.$t('Coupon code not found!', { code: this.discount.code })
} else {
this.error = 'Something goes wrong when trying to send coupon code. Please try again later.'
this.error = this.$t('Something goes wrong when trying to send coupon code. Please try again later.')
}
})
},
Expand All @@ -103,9 +103,9 @@ export default {
this.loader = false

if (error.status === 404) {
this.error = `Failed when trying to delete: '${this.discount.code}' coupon code. Coupon code not found!`
this.error = this.$t('Failed when trying to delete coupon code', { code: this.discount.code })
} else {
this.error = 'Something goes wrong when trying to delete coupon code. Please try again later.'
this.error = this.$t('Something goes wrong when trying to delete coupon code')
}
})
}
Expand Down
6 changes: 3 additions & 3 deletions view/frontend/web/js/components/PaymentMethods.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<form>
<h2>
Payment methods
{{ $t('Payment methods') }}
</h2>
<div v-if="paymentMethods.length">
<div
Expand All @@ -26,12 +26,12 @@
&& !$v.selectedPaymentMethod.required
"
>
This field is required!
{{ $t('This field is required!') }}
</span>
</div>
<div v-else>
<p>
In this country we don't handle any payment methods.
{{ $t('In this country we don\'t handle any payment methods') }}
</p>
</div>
</form>
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/js/components/ProductsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class="products-list"
>
<h2>
Product List
{{ $t('Product List') }}
</h2>
<ul class="products">
<ProductsListItem
Expand Down
11 changes: 6 additions & 5 deletions view/frontend/web/js/components/ProductsListItem.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<template>
<li class="product">
<p class="products__title">
Product name:
{{ $t('Product name') }}
<strong>
{{ product.name }}
</strong>
</p>

<span class="product__price">
Price:
{{ $t('Price') }}

<strong>
{{ product.price | currency }}
</strong>
</span>

<div class="products__handler">
<p class="products__information">
Product details:
{{ $t('Price details') }}
</p>

<template v-for="detail in JSON.parse(product.options)">
Expand All @@ -32,15 +33,15 @@
</template>

<span class="products__detail">
Qty:
{{ $t('Qty') }}
<strong>
{{ product.qty }}
</strong>
</span>

<template v-if="product.discount_percent > 0">
<span class="product__detail">
Discount: {{ product.discount_percent }}%
{{ $t('Discount') }}: {{ product.discount_percent }}%
</span>
</template>
</div>
Expand Down
Loading