From 9e5fc5bf1ee8e28ae50bc45b307ff426da82f2d3 Mon Sep 17 00:00:00 2001 From: Jitendra Singh Date: Wed, 15 Jan 2020 19:03:07 +0530 Subject: [PATCH] Issue #2054 fixed --- packages/Webkul/Product/src/Type/Bundle.php | 25 ++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/Webkul/Product/src/Type/Bundle.php b/packages/Webkul/Product/src/Type/Bundle.php index 3aa680172..7d59d2279 100644 --- a/packages/Webkul/Product/src/Type/Bundle.php +++ b/packages/Webkul/Product/src/Type/Bundle.php @@ -405,7 +405,9 @@ class Bundle extends AbstractType */ public function prepareForCart($data) { - if (! isset($data['bundle_options'])) + $data['bundle_options'] = array_filter($this->validateBundleOptionForCart($data['bundle_options'])); + + if (! isset($data['bundle_options']) || ! count($data['bundle_options'])) return trans('shop::app.checkout.cart.integrity.missing_options'); $products = parent::prepareForCart($data); @@ -490,6 +492,27 @@ class Bundle extends AbstractType && $options1['bundle_option_qty'] == $this->getOptionQuantities($options2); } + /** + * Remove invalid options from add to cart request + * + * @param array $data + * @return array + */ + public function validateBundleOptionForCart($data) + { + foreach ($data as $key => $value) { + if (is_array($value)) { + $data[$key] = $this->validateBundleOptionForCart($value); + } elseif ($value && $value) { + $data[$key] = (int)$value; + } else { + unset($data[$key]); + } + } + + return $data; + } + /** * Returns additional information for items *