我有一些foreach循环,他们获得了一些产品列表,每个产品都有id
和qty
字段。
所以我想在一些变量中得到所有的id和数量:
$var = array(3) {
[0] => array(2) { //product1
["id"] => int(1) "2"
["qty"] => int(2) "50"
}
[1] => array(2) { //product2
["id"] => int(1) "6"
["qty"] => int(2) "30"
}
[2] => array(2) { //product3
["id"] => int(1) "9"
["qty"] => int(2) "99"
}
}
我的产品:
<?php foreach ($_productCollection as $prod) : ?>
<?php if($prod->isSaleable()): ?>
<?php //echo $this->getChildHtml('addtocart') ?>
<form action="<?php echo $this->getAddToCartUrl($prod) ?>" method="post" id="product_addtocart_form_<?php echo $prod->getId()?>"<?php if($_product->getOptions()): ?> enctype="multipart/form-data"<?php endif; ?>>
<?php if(!$prod->isGrouped()): ?>
<?php $productId = $prod->getId(); ?>
<?php $productCartQty = $this->getCartQty($prod); ?>
<div class="border-new-cart-button">
<span class="plus qty-add" style="float:right;" onclick="plusQty('qty-<?php echo $productId ?>')"><i class="fa fa-plus"></i></span>
<input type="text" class="input-qty-product number-control" title="Qty" value="<?php echo /*$this->getProductDefaultQty() * */ 0 ?>" name="qty" id="qty-<?php echo $productId ?>"/>
<span class="moins qty-remove" style="float:right;" onclick="minusQty('qty-<?php echo $productId ?>')"><i class="fa fa-minus"></i></span>
</div>
<?php endif; ?>
<button type="button" class="btn add-to-cart" onclick="this.form.submit()"><span><?php echo $this->__('Valider') ?></span></button>
<input type="hidden" name="products[]" value="<?php echo $_product->getId() ?>" />
</form>
<?php endif;?>
<?php endforeach; ?>
在前面看起来像:
<form action="http://domaine.com/checkout/cart/add/uenc/aHR0cDovL3Bmc2ZvLnByb2pldHMtcHJlcHJvZC5jb20vaG9tbWUvdmV0ZW1lbnRzL3Qtc2hpcnRzL3Qtc2hpcnQtb3ZlcnNpemUuaHRtbA,,/product/1641/form_key/wtBQE1VnebqTbkym/" method="post" id="product_addtocart_form_1641">
<div class="border-new-cart-button">
<span class="plus qty-add" style="float:right;" onclick="plusQty('qty-1641')"><i class="fa fa-plus"></i></span>
<input class="input-qty-product number-control" title="Qty" value="0" name="qty" id="qty-1641" type="text">
<span class="moins qty-remove" style="float:right;" onclick="minusQty('qty-1641')"><i class="fa fa-minus"></i></span>
</div>
<button type="button" class="btn add-to-cart" onclick="this.form.submit()"><span>Validate</span></button>
<input name="products[]" value="1639" type="hidden">
</form>