@@ -45,18 +45,18 @@ public function __construct(
4545 /**
4646 * {@inheritdoc}
4747 * @param array $data Parameters
48- * <pre>
49- * $data = [
50- * 'cart_id' => (int) Cart ID. Required.
51- * 'product_id' => (int) Product ID. Required.
52- * 'selections' => (array) array of options selections. Required.
53- * 'qty' => (int) Quantity. Optional. Default: 1.
54- * ]
55- * </pre>
5648 * $data['selections'] can be supplied in following formats:
5749 * - [["$product1.id$"], ["$product2.id$"]]
5850 * - [[{"product_id":"$product1.id$","qty":1}], [{"product_id":"$product2.id$","qty":1}]]
5951 * - To skip an option, pass empty array [["$product1.id$"], [], ["$product2.id$"]]
52+ * <pre>
53+ * $data = [
54+ * 'cart_id' => (int) Cart ID. Required.
55+ * 'product_id' => (int) Product ID. Required.
56+ * 'selections' => (array) array of options selections. Required.
57+ * 'qty' => (int) Quantity. Optional. Default: 1.
58+ * ]
59+ * </pre>
6060 */
6161 public function apply (array $ data = []): ?DataObject
6262 {
@@ -71,25 +71,25 @@ public function apply(array $data = []): ?DataObject
7171 $ options ->appendSelections ($ selections , true );
7272 $ optionsList = array_values ($ options ->getItems ());
7373 foreach ($ data ['selections ' ] as $ index => $ selections ) {
74- if (!empty ($ selections )) {
75- $ option = $ optionsList [$ index ];
76- foreach ($ selections as $ item ) {
77- if (is_array ($ item )) {
78- $ productId = (int ) $ item ['product_id ' ];
79- $ qty = $ item ['qty ' ] ?? 1 ;
80- } else {
81- $ productId = (int ) $ item ;
82- $ qty = 1 ;
83- }
84- foreach ($ option ->getSelections () as $ selection ) {
85- if (((int ) $ selection ->getProductId ()) === $ productId ) {
86- $ buyRequest ['bundle_option ' ][$ option ->getId ()][] = $ selection ->getSelectionId ();
87- $ buyRequest ['bundle_option_qty ' ][$ option ->getId ()][$ selection ->getSelectionId ()] = $ qty ;
88- break ;
89- }
90- }
91- }
92- }
74+ if (!empty ($ selections )) {
75+ $ option = $ optionsList [$ index ];
76+ foreach ($ selections as $ item ) {
77+ if (is_array ($ item )) {
78+ $ productId = (int )$ item ['product_id ' ];
79+ $ qty = $ item ['qty ' ] ?? 1 ;
80+ } else {
81+ $ productId = (int )$ item ;
82+ $ qty = 1 ;
83+ }
84+ foreach ($ option ->getSelections () as $ selection ) {
85+ if (((int )$ selection ->getProductId ()) === $ productId ) {
86+ $ buyRequest ['bundle_option ' ][$ option ->getId ()][] = $ selection ->getSelectionId ();
87+ $ buyRequest ['bundle_option_qty ' ][$ option ->getId ()][$ selection ->getSelectionId ()] = $ qty ;
88+ break ;
89+ }
90+ }
91+ }
92+ }
9393 }
9494 return parent ::apply (
9595 [
0 commit comments