@@ -45,18 +45,18 @@ public function __construct(
45
45
/**
46
46
* {@inheritdoc}
47
47
* @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>
56
48
* $data['selections'] can be supplied in following formats:
57
49
* - [["$product1.id$"], ["$product2.id$"]]
58
50
* - [[{"product_id":"$product1.id$","qty":1}], [{"product_id":"$product2.id$","qty":1}]]
59
51
* - 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>
60
60
*/
61
61
public function apply (array $ data = []): ?DataObject
62
62
{
@@ -71,25 +71,25 @@ public function apply(array $data = []): ?DataObject
71
71
$ options ->appendSelections ($ selections , true );
72
72
$ optionsList = array_values ($ options ->getItems ());
73
73
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
+ }
93
93
}
94
94
return parent ::apply (
95
95
[
0 commit comments