Whenever I try to insert multiple rows with a loop, the record is made
but rewritten over in the loop. The following code results in one new
record in order_products no matter the number of cart_products.
$cart_products = $this->requestAction('/shopping_carts/getCart');
foreach($cart_products as $product) {
$this->data['OrderProduct']['order_id'] = $order_id;
$this->data['OrderProduct']['sku'] =
$product['ProductColor']['sku'];
$this->data['OrderProduct']['name'] =
$product['Product']['name'];
$this->data['OrderProduct']['color'] =
$product['ProductColor']['name'];
$this->data['OrderProduct']['size'] =
$product['ProductSize']['name'];
$this->data['OrderProduct']['quantity'] =
$product['ShoppingCart']['quantity'];
$this->data['OrderProduct']['price'] =
$product['Product']['price'];
$this->OrderProduct->save($this->data['OrderProduct']);
}
I've also tried this with no luck:
foreach($cart_products as $product) {
$this->OrderProduct->saveField('order_id', $order_id);
$this->OrderProduct->id =
$this->OrderProduct->getLastInsertID();
$this->OrderProduct->saveField('sku',
$product['ProductColor']['sku']);
$this->OrderProduct->saveField('name',
$product['Product']['name']);
$this->OrderProduct->saveField('color',
$product['ProductColor']['name']);
$this->OrderProduct->saveField('size',
$product['ProductSize']['name']);
$this->OrderProduct->saveField('quantity',
$product['ShoppingCart']['quantity']);
$this->OrderProduct->saveField('price',
$product['Product']['price']);
}
Thanks in advance for the help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---