This is the code:
function create_order_with_custom_products()
{
$orderGenerator = new OrderGenerator();
$orderGenerator->setCustomer(6907);
$orderGenerator->createOrder(array(
// Add configurable product
array(
'product' => 30151,
'qty' => 1
), array(
'product' => 30150,
'qty' => 2
),
));
}
I have to create array with such structure:
array(
'product' => 30151,
'qty' => 1
), array(
'product' => 30150,
'qty' => 2
),
I am trying to create an array with same structure like that:
foreach($ItemsInCart['productid'] as $key=>$value){
$ProductId = $value;
$ProductQty = $ItemsInCart["productqty"][$key];
$product_id = $ProductId; // Replace id with your product id
$qty = $ProductQty; // Replace qty with your qty
$ItemsId[] = ['product' => $ProductId, 'qty' => $ProductQty];
}
This gives me result of:
Array ( [0] => Array ( [product] => 30143 [qty] => 1 ) [1] => Array ( [product] => 30144 [qty] => 2 ) [2] => Array ( [product] => 30145 [qty] => 3 ) [3] => Array ( [product] => 30146 [qty] => 4 ) [4] => Array ( [product] => 30147 [qty] => 5 ) )
All i want to know is why this :
function create_order_with_custom_products()
{
$orderGenerator = new OrderGenerator();
$orderGenerator->setCustomer(6907);
$orderGenerator->createOrder(array(
// Add configurable product
array(
'product' => 30151,
'qty' => 1
), array(
'product' => 30150,
'qty' => 2
),
));
}
Is not the same as this:
function create_order_with_custom_products()
{
$orderGenerator = new OrderGenerator();
$orderGenerator->setCustomer(6907);
$orderGenerator->createOrder(array($ItemsId));
}
Why the second approach is not working, where is my mistake?
$ItemsId[]["product"] = $ProductId; $ItemsId[]["qty"] = $ProductQty;with$ItemsId[] = ['product' => $ProductId, 'qty' => $ProductQty];