Fix JSON shop load
Signed-off-by: Egor Savkin <es@m-labs.hk>
This commit is contained in:
parent
1a7d44c121
commit
f93cf142f0
|
@ -258,6 +258,7 @@ class Layout extends React.PureComponent {
|
|||
conf_obj.items = conf_obj.items.map(function (item) {
|
||||
return {
|
||||
pn: item.pn,
|
||||
options: item.options ? item.options : null,
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -606,7 +607,6 @@ class ProductCartItem extends React.PureComponent {
|
|||
|
||||
|
||||
if (data && data.options) {
|
||||
console.log(data.options_data);
|
||||
options = data.options;
|
||||
if (!data.options_data) data.options_data = {};
|
||||
options_data = data.options_data;
|
||||
|
@ -867,7 +867,6 @@ class Cart extends React.PureComponent {
|
|||
let itemData;
|
||||
if (data.itemsData && index in data.itemsData) {
|
||||
itemData = data.itemsData[index];
|
||||
console.log(itemData.options_data);
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -1422,7 +1421,7 @@ class OrderSumary extends React.PureComponent {
|
|||
let alert;
|
||||
let warning;
|
||||
|
||||
if (itemsData[index]) {
|
||||
if (itemsData[index] && itemsData[index].warnings) {
|
||||
alert = itemsData[index];
|
||||
const warningsKeys = Object.keys(alert.warnings);
|
||||
if (warningsKeys && warningsKeys.length > 0) {
|
||||
|
@ -1459,7 +1458,7 @@ class OrderSumary extends React.PureComponent {
|
|||
) : (
|
||||
<img
|
||||
style={{'marginLeft': '10px'}}
|
||||
className="alert-warning"
|
||||
className="alert-info"
|
||||
src="/images/shop/icon-customize.svg"
|
||||
/>
|
||||
)}
|
||||
|
@ -1827,11 +1826,14 @@ class Shop extends React.PureComponent {
|
|||
type: this.state.currentMode,
|
||||
};
|
||||
const clonedCart = Array.from(this.state.columns.cart.items);
|
||||
console.log(clonedCart);
|
||||
const clonedCartData = Array.from(this.state.columns.cart.itemsData);
|
||||
console.log(clonedCartData);
|
||||
for (const i in clonedCart) {
|
||||
const item = clonedCart[i];
|
||||
const item_data = clonedCartData[i];
|
||||
crate.items.push({
|
||||
'pn': item.name_number
|
||||
'pn': item.name_number,
|
||||
'options': item_data.options_data ? item_data.options_data : null,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1855,9 +1857,11 @@ class Shop extends React.PureComponent {
|
|||
if (!customconf) {return; }
|
||||
|
||||
const items = this.props.data.items;
|
||||
console.trace(customconf);
|
||||
const self = this;
|
||||
|
||||
let new_items = [];
|
||||
let new_items_data = [];
|
||||
|
||||
|
||||
this.setState({
|
||||
|
@ -1878,14 +1882,15 @@ class Shop extends React.PureComponent {
|
|||
...items[key],
|
||||
}, {
|
||||
id: uuidv4(),
|
||||
options_data: item.options ? item.options : null,
|
||||
}));
|
||||
new_items_data.push({options_data: item.options? item.options : null});
|
||||
}
|
||||
});
|
||||
|
||||
return item;
|
||||
});
|
||||
|
||||
|
||||
this.setState({
|
||||
...this.state,
|
||||
columns: {
|
||||
|
@ -1893,6 +1898,7 @@ class Shop extends React.PureComponent {
|
|||
cart: {
|
||||
...this.state.columns.cart,
|
||||
items: new_items,
|
||||
itemsData: new_items_data,
|
||||
},
|
||||
},
|
||||
currentMode: customconf.type,
|
||||
|
@ -1906,10 +1912,13 @@ class Shop extends React.PureComponent {
|
|||
type: this.state.currentMode,
|
||||
};
|
||||
const clonedCart = Array.from(this.state.columns.cart.items);
|
||||
const clonedCartData = Array.from(this.state.columns.cart.itemsData);
|
||||
for (const i in clonedCart) {
|
||||
const item = clonedCart[i];
|
||||
const item_data = clonedCartData[i];
|
||||
crate.items.push({
|
||||
'pn': item.name_number,
|
||||
'options': item_data.options_data ? item_data.options_data : null,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2042,8 +2051,6 @@ class Shop extends React.PureComponent {
|
|||
|
||||
const itemsCloned = Array.from(newItems);
|
||||
const itemsData = [];
|
||||
console.log(prevItems);
|
||||
console.log(this.state);
|
||||
const rules = {};
|
||||
|
||||
|
||||
|
@ -2136,9 +2143,6 @@ class Shop extends React.PureComponent {
|
|||
rules[ddkali.rules.follow.type] = {...ddkali.rules.follow};
|
||||
}
|
||||
}
|
||||
console.log(idx);
|
||||
if (idx in this.state.columns.cart.itemsData && this.state.columns.cart.itemsData[idx].options_data)
|
||||
itemsData[idx].options_data = this.state.columns.cart.itemsData[idx].options_data;
|
||||
}
|
||||
|
||||
if (idxK.length === 0) {
|
||||
|
@ -2322,6 +2326,13 @@ class Shop extends React.PureComponent {
|
|||
}
|
||||
}
|
||||
|
||||
itemsCloned.forEach((_elem, idx) => {
|
||||
if (!(idx in itemsData)) itemsData[idx] = {};
|
||||
if (idx in this.state.columns.cart.itemsData && this.state.columns.cart.itemsData[idx].options_data) {
|
||||
itemsData[idx].options_data = this.state.columns.cart.itemsData[idx].options_data;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// update state with rules
|
||||
this.setState({
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
import React, {Component} from "react";
|
||||
import jsonLogic from 'json-logic-js';
|
||||
import {v4 as uuidv4} from 'uuid';
|
||||
|
||||
// https://stackoverflow.com/a/70511311
|
||||
const trueTypeOf = (obj) => Object.prototype.toString.call(obj).slice(8, -1).toLowerCase();
|
||||
|
@ -15,7 +14,7 @@ class Radio extends Component {
|
|||
target: props.target,
|
||||
outvar: props.outvar,
|
||||
variants: props.variants,
|
||||
variant: props.variants[0],
|
||||
variant: props.outvar in props.data ? props.data[props.outvar] : props.variants[0],
|
||||
id: props.id
|
||||
};
|
||||
|
||||
|
@ -60,8 +59,8 @@ class Radio extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
function RadioWrapper(target, id, {title, variants, outvar}) {
|
||||
return <Radio target={target} title={title} variants={variants} outvar={outvar} key={id} id={id}/>;
|
||||
function RadioWrapper(target, id, data, {title, variants, outvar}) {
|
||||
return <Radio target={target} title={title} variants={variants} outvar={outvar} key={id} id={id} data={data} />;
|
||||
}
|
||||
|
||||
|
||||
|
@ -94,7 +93,7 @@ export default function ProcessOptions({options, data, target, id}) {
|
|||
trueTypeOf(options.args) === "object"
|
||||
) {
|
||||
if (options.type in componentsList) {
|
||||
return componentsList[options.type](target, id + options.type, options.args);
|
||||
return componentsList[options.type](target, id + options.type, data, options.args);
|
||||
} else {
|
||||
return componentsList["Default"](options.type, id + "missing");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue