Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
Fix shipping method details edit
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed May 22, 2019
1 parent 97de6bb commit 0a252e3
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
return {
title: '',
loaded: false,
method: {}
method: {},
attribute_groups: [],
languages: []
}
},
components: {
Expand All @@ -23,6 +25,7 @@
}
},
created() {
this.loadLanguages();
this.loadMethod(this.id);
},
mounted() {
Expand All @@ -37,23 +40,76 @@
Dispatcher.add('save-shipping-method', this);
},
methods: {
/**
* Loads languages
* @return
*/
loadLanguages() {
apiRequest.send('get', 'languages', [], []).then(response => {
response.data.forEach(lang => {
this.languages.push({
label: lang.name,
value: lang.lang,
content: '<span class=\'flag-icon flag-icon-' + lang.iso + '\'></span> ' + lang.name
});
});
});
},
save() {
apiRequest.send('PUT', '/shipping/' + this.method.id, this.method).then(response => {
CandyEvent.$emit('notification', {
level: 'success'
});
})
},
decorate(data) {

this.attribute_groups = data.attribute_groups.data;

// Get all groups associated to this product.
let groups = [];

_.each(data.attributes.data, attribute => {
if (!data.attribute_data[attribute.handle]) {
this.$set(data.attribute_data, attribute.handle, {
webstore: {
en: ""
}
});
}

let exists = _.find(groups, group => {
return group.handle == attribute.group.data.handle;
});
if (attribute.group && !exists) {
let group = attribute.group.data;
let attributes = group.attributes.data;
_.each(attributes, (att, index) => {
if (!data.attribute_data[att.handle]) {
delete attributes[index];
}
});
group.attributes.data = _.filter(attributes);
groups.push(group);
}
});

groups = _.orderBy(groups, 'position', 'asc');

this.attribute_groups = groups;
this.method = data;
},

/**
* Loads the product by its encoded ID
* @param {String} id
*/
loadMethod(id) {
apiRequest.send('get', '/shipping/' + id, {}, {
includes: 'prices.customer_groups,prices.currency,prices.zone,zones,channels,attribute_groups.attributes,users'
includes: 'attributes.group.attributes,prices.customer_groups,prices.currency,prices.zone,zones,channels,attribute_groups.attributes,users'
})
.then(response => {
this.method = response.data;
this.decorate(response.data);
this.loaded = true;
CandyEvent.$emit('title-changed', {
title: this.method
Expand All @@ -73,7 +129,11 @@
<transition name="fade">
<candy-tabs initial="save-shipping-method">
<candy-tab name="Basic information" dispatch="save-shipping-method" :selected="true">
<candy-shipping-details :method="method"></candy-shipping-details>
<candy-tabs nested="true">
<candy-tab v-for="(group, index) in attribute_groups" :name="group.name" :handle="group.id" :key="group.id" :selected="index == 0 ? true : false" dispatch="shipping-details">
<candy-shipping-details :method="method" :languages="languages" :group="group"></candy-shipping-details>
</candy-tab>
</candy-tabs>
</candy-tab>
<candy-tab name="Availability & Pricing">
<candy-tabs nested="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,27 @@
export default {
data() {
return {
groups: [],
customerGroups: [],
languages: [],
request: apiRequest
}
},
props: {
method: {
type: Object
},
languages: {
type: Array
},
channels: {
type: Array
},
group: {
type: Object,
default() {
return [];
}
}
},
mounted() {
this.loadLanguages();
},
methods: {
/**
* Loads languages
* @return
*/
loadLanguages() {
apiRequest.send('get', 'languages', [], []).then(response => {
response.data.forEach(lang => {
this.languages.push({
label: lang.name,
value: lang.lang,
content: '<span class=\'flag-icon flag-icon-' + lang.iso + '\'></span> ' + lang.name
});
});
});
},
getChannels(channels) {
let arr = [];
channels.forEach(channel => {
Expand Down Expand Up @@ -65,25 +56,9 @@

<template>
<div>
<candy-tabs nested="true">
<candy-tab v-for="(group, index) in method.attribute_groups.data" :name="group.name" :handle="group.id" :key="group.id" :selected="index == 0 ? true : false" dispatch="collection-details">
<candy-attribute-translatable
:languages="languages"
:attributes="group.attributes.data"
:attributeData="method.attribute_data"
:channels="getChannels(method.channels.data)"
:request="request"
>
</candy-attribute-translatable>
<div class="form-group">
<label>Carrier</label>
<select class="form-control selectize" v-model="method.type">
<option value="">-- Please select</option>
<option value="standard">Standard</option>
<option value="dhl">DHL</option>
</select>
</div>
</candy-tab>
</candy-tabs>
<candy-attribute-translatable :languages="languages" :channels="getChannels(method.channels.data)"
:attributes="group.attributes.data" :attributeData="method.attribute_data"
:request="request">
</candy-attribute-translatable>
</div>
</template>

0 comments on commit 0a252e3

Please sign in to comment.