Here is my code:
$printcoll = $_SESSION['ObjColl'];
for($i = 0;$i < $printcoll->getlineCount();$i++){
$li = $printcoll -> getLineItem($i);
$item = $li->getItem();
if ($item instanceof Product) {
print "Bike ID - ";
}
print $item-> getId();
if ($item instanceof Product) {
print "  Price £";
}
print $item-> getPrice();
if ($item instanceof Product) {
print "  Quantity - ";
}
print $li->getQuantity();
echo "</br>";
Here is what the ObjectCollection looks like:
ObjectCollection Object ( [line_items_array:ObjectCollection:private] => Array ( [0] => LineItem Object ( [item:LineItem:private] => Product Object ( [id] => 1 [name] => Yamaha [price] => 10000 ) [quantity:LineItem:private] => 3 ) [1] => LineItem Object ( [item:LineItem:private] => Product Object ( [id] => 4 [name] => Kawasaki [price] => 12000 ) [quantity:LineItem:private] => 7 )
The output of the For loop is:
Bike ID - 1 Price £10000 Quantity - 3
Bike ID - 4 Price £12000 Quantity - 7
The ObjectCollection is made up of Product objects. How do i add an option into the for loop so the user can delete a "Product" object out of the ObjectCollection class?
public function delLineItem($line_item) is the function within the ObjectCollection class. But how do i integrate that into a OPTION in the for loop because the user may or may not to delete it?
So for example, i want the output of the for loop to be :
Bike ID - 1 Price £10000 Quantity - 3 DELETE BUTTON
So if the user clicks on the delete button, it will delete that specific product out of the object collection. Thanks