Allow disabling stock for certain products
parent
1c4303018a
commit
2a78fe5290
lib/schemas
locales
public/javascripts
routes
views
|
@ -162,8 +162,9 @@
|
||||||
"productPublished": true,
|
"productPublished": true,
|
||||||
"productTags": "subscription",
|
"productTags": "subscription",
|
||||||
"productOptions": "",
|
"productOptions": "",
|
||||||
"productStock": null,
|
"productStock": 0,
|
||||||
"productSubscription": "plan_XXXXXXXXXXXXXX"
|
"productSubscription": "plan_XXXXXXXXXXXXXX",
|
||||||
|
"productStockDisable": true
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"customers": [
|
"customers": [
|
||||||
|
|
|
@ -38,6 +38,9 @@
|
||||||
},
|
},
|
||||||
"productStock": {
|
"productStock": {
|
||||||
"type": ["number", "null"]
|
"type": ["number", "null"]
|
||||||
|
},
|
||||||
|
"productStockDisable": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errorMessage": {
|
"errorMessage": {
|
||||||
|
|
|
@ -35,6 +35,9 @@
|
||||||
},
|
},
|
||||||
"productStock": {
|
"productStock": {
|
||||||
"type": ["number", "null"]
|
"type": ["number", "null"]
|
||||||
|
},
|
||||||
|
"productStockDisable": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errorMessage": {
|
"errorMessage": {
|
||||||
|
|
|
@ -205,5 +205,6 @@
|
||||||
"Logout": "Logout",
|
"Logout": "Logout",
|
||||||
"Company": "Company",
|
"Company": "Company",
|
||||||
"View": "View",
|
"View": "View",
|
||||||
"Related products": "Related products"
|
"Related products": "Related products",
|
||||||
|
"Disable stock tracking": "Disable stock tracking"
|
||||||
}
|
}
|
|
@ -244,6 +244,7 @@ $(document).ready(function (){
|
||||||
productPrice: $('#productPrice').val(),
|
productPrice: $('#productPrice').val(),
|
||||||
productPublished: $('#productPublished').val(),
|
productPublished: $('#productPublished').val(),
|
||||||
productStock: $('#productStock').val(),
|
productStock: $('#productStock').val(),
|
||||||
|
productStockDisable: $('#productStockDisable').is(':checked'),
|
||||||
productDescription: $('#productDescription').val(),
|
productDescription: $('#productDescription').val(),
|
||||||
productPermalink: $('#productPermalink').val(),
|
productPermalink: $('#productPermalink').val(),
|
||||||
productOptions: $('#productOptions').val(),
|
productOptions: $('#productOptions').val(),
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -548,6 +548,8 @@ router.post('/product/addtocart', async (req, res, next) => {
|
||||||
|
|
||||||
// If stock management on check there is sufficient stock for this product
|
// If stock management on check there is sufficient stock for this product
|
||||||
if(config.trackStock){
|
if(config.trackStock){
|
||||||
|
// Only if not disabled
|
||||||
|
if(product.productStockDisable !== true){
|
||||||
// If there is more stock than total (ignoring held)
|
// If there is more stock than total (ignoring held)
|
||||||
if(productQuantity > product.productStock){
|
if(productQuantity > product.productStock){
|
||||||
return res.status(400).json({ message: 'There is insufficient stock of this product.' });
|
return res.status(400).json({ message: 'There is insufficient stock of this product.' });
|
||||||
|
@ -584,6 +586,7 @@ router.post('/product/addtocart', async (req, res, next) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const productPrice = parseFloat(product.productPrice).toFixed(2);
|
const productPrice = parseFloat(product.productPrice).toFixed(2);
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,8 @@ router.post('/admin/product/insert', restrict, checkAccess, async (req, res) =>
|
||||||
productOptions: productOptions || null,
|
productOptions: productOptions || null,
|
||||||
productComment: common.checkboxBool(req.body.productComment),
|
productComment: common.checkboxBool(req.body.productComment),
|
||||||
productAddedDate: new Date(),
|
productAddedDate: new Date(),
|
||||||
productStock: common.safeParseInt(req.body.productStock) || null
|
productStock: common.safeParseInt(req.body.productStock) || null,
|
||||||
|
productStockDisable: common.convertBool(req.body.productStockDisable)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate the body again schema
|
// Validate the body again schema
|
||||||
|
@ -251,7 +252,8 @@ router.post('/admin/product/update', restrict, checkAccess, async (req, res) =>
|
||||||
productTags: req.body.productTags,
|
productTags: req.body.productTags,
|
||||||
productOptions: productOptions || null,
|
productOptions: productOptions || null,
|
||||||
productComment: common.checkboxBool(req.body.productComment),
|
productComment: common.checkboxBool(req.body.productComment),
|
||||||
productStock: common.safeParseInt(req.body.productStock) || null
|
productStock: common.safeParseInt(req.body.productStock) || null,
|
||||||
|
productStockDisable: common.convertBool(req.body.productStockDisable)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate the body again schema
|
// Validate the body again schema
|
||||||
|
|
|
@ -37,12 +37,22 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{#if config.trackStock}}
|
{{#if config.trackStock}}
|
||||||
<div class="col-sm-6">
|
<div class="row">
|
||||||
|
<div class="col-sm-5 ml-3">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="productStock" class="control-label">{{ @root.__ "Stock level" }}</label>
|
<label for="productStock" class="control-label">{{ @root.__ "Stock level" }}</label>
|
||||||
<input type="number" id="productStock" class="form-control" value="{{result.productStock}}" step="any" />
|
<input type="number" id="productStock" class="form-control" value="{{result.productStock}}" step="any" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-sm-5">
|
||||||
|
<label for="productStockDisable" class="control-label">{{ @root.__ "Disable stock tracking" }}</label>
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input class="productStockDisable" type="checkbox" {{checkedState result.productStockDisable}} id="productStockDisable">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
<div class="col-12">
|
<div class="col-12">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
Loading…
Reference in New Issue