mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-30 20:27:07 +09:00
Validate add-on configs before adding to cart (#1313)
* Validate addon configs before adding to cart * Fix spelling mistake
This commit is contained in:
1 parent
64d60e254a
commit
b65a75fcf7
1 file changed
+16
@@ -159,12 +159,28 @@ class Guest extends \Api_Abstract
|
||||
$required = [
|
||||
'id' => 'Product id not passed',
|
||||
];
|
||||
|
||||
$this->di['validator']->checkRequiredParamsForArray($required, $data);
|
||||
|
||||
$cart = $this->getService()->getSessionCart();
|
||||
|
||||
$product = $this->di['db']->getExistingModelById('Product', $data['id'], 'Product not found');
|
||||
|
||||
if ($product->is_addon) {
|
||||
throw new \Box_Exception('Addon products cannot be added separately.');
|
||||
}
|
||||
|
||||
$validAddons = json_decode($product->addons ?? '');
|
||||
if(empty($validAddons)){
|
||||
$validAddons = [];
|
||||
}
|
||||
|
||||
foreach ($data['addons'] as $addon => $properties) {
|
||||
if($properties['selected'] && !in_array($addon, $validAddons)){
|
||||
throw new \Box_Exception('One or more of your selected addons are not valid for the associated product.');
|
||||
}
|
||||
}
|
||||
|
||||
// reset cart by default
|
||||
if (!isset($data['multiple']) || !$data['multiple']) {
|
||||
$this->reset();
|
||||
|
||||
Reference in new issue
Block a user