У меня есть функция AddtoCart, которая выдает неопределенную ошибку при нажатии, чтобы добавить продукты в корзину.
Ошибка в этой функции, index.js
componentWillUpdate(nextProps, nextState) {
if (nextState.cartPopup && nextProps.reducerKeyProductCartPage !== this.props.reducerKeyProductCartPage && nextProps.reducerKeyProductCartPage) {
if (nextProps.reducerKeyProductCartPage.status && nextProps.reducerKeyProductCartPage.status[0].toLowerCase().includes("error")) {
this.notify(nextProps.reducerKeyProductCartPage.message[0]);
}
else {
this.notify(nextProps.reducerKeyProductCartPage.message[0], "success");
}
this.setState({ cartPopup: false });
}
}
Ниже приведена функция добавления в корзину:
addToCart = (data) => {
this.setState({ cartPopup: true, deleteCart: false });
let customerId = cookie.load("customerId") ? cookie.load("customerId") : 0;
let getUrl = '';
let stateProductData = {}
if (customerId) {
getUrl = constant.BaseUrl + this.state.languageValue + "-" + this.state.storeValue + "/rest/V1/customer/addtocart";
stateProductData = { "customer_id": customerId, "lang": this.state.languageValue + "_" + this.state.storeValue, "product_id": data, "quantity": 1 }
}
else {
getUrl = constant.BaseUrl + this.state.languageValue + "-" + this.state.storeValue + "/rest/V1/customer/guestaddtocart";
stateProductData = { "quote_id": cookie.load("cartValue"), "lang": this.state.languageValue + "_" + this.state.storeValue, "product_id": data, "quantity": 1 }
}
this.props.commonGateway({
reqData: stateProductData,
url: getUrl, method: 'POST',
resource: "cartProduct", reducerKey: "reducerKeyProductCartPage"
});
this.props.commonGatewayRequestDone({ reducerKey: "reducerKeyProductCartStatus" });
}
Ниже приведен метод рендеринга, который добавляет кнопку «Добавить в корзину» в другом компоненте:
return (
<div>
<MainContainer block={idx + 2} fetchData={this.fetchData} data={this.props["reducerKeyFetchLandingPage" + (idx + 2)] ? this.props["reducerKeyFetchLandingPage" + (idx + 2)] : ""} addToCart={this.addToCart} addToWishList={this.addToWishList} rtl={this.state.languageValue} />
</div>
);
снимок экрана с ошибкой ![enter image description here](https://i.stack.imgur.com/aoTmc.png)