vendredi 1 juillet 2016

Combine 2 differect foreach [duplicate]

This question already has an answer here:

I want to do this: For each product that there is in the cart to echo id, quantity and sales Price.

I found out that id and quantity are inside:

$this->cart->products 

and sales Price is inside:

$this->cart->pricesUnformatted

So, i need to run one:

foreach($this->cart->products as $product) {
        $wantedproductid = $product->virtuemart_product_id;
        $wantedproductquantity = $product->quantity;
        echo $wantedproductid . '<br>' . $wantedproductquantity . '<br>' ;
}

This brings me id and quantity. Now, i need somehow while running this foreach to run also this:

foreach ($this->cart->pricesUnformatted as $productt) {
    $wantedpricecart = trim($productt["salesPrice"]);
    if (!empty($inter)) {
         echo $wantedpricecart;
}

This foreach brings me for each product the sales Price.

Any idea of how to combine those 2 in order for me to have at the end for each product, id and sales price at once?

To understand what i mean i want at the end to generate something like:

$cartlinkwi .= 'lw("addItem", {id: "' . $wantedproductid . '",price: "' . $wantedpricecart . '",quantity: "' . $wantedproductquantity . '"});';

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire