Skip to content

Commit

Permalink
Added quantity processes for the main product.
Browse files Browse the repository at this point in the history
  • Loading branch information
rasseljandavid committed Jul 14, 2011
1 parent c3b3c3e commit 27ea4aa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
16 changes: 14 additions & 2 deletions framework/modules/ecommerce/controllers/cartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function addItem() {
flash('message', "Please select a product and quantity from the options listed below to add to your cart.");
redirect_to(array('controller'=>'store','action'=>'show','id'=>$this->params['product_id']));
}
//check for multiple product adding
//check for multiple product adding
if (isset($this->params['prod-quantity']))
{
//we are adding multiple children, so we approach a bit different
Expand Down Expand Up @@ -77,6 +77,18 @@ function addItem() {

$product = new $product_type($this->params['product_id'], true, true); //need true here?
//Check the Main Product quantity
if (isset($this->params['quantity']))
{
if(((int)$this->params['quantity']) < $product->minimum_order_quantity)
{
flash('message', "Please enter a quantity equal or greater than the minimum order quantity.");
redirect_to(array('controller'=>'store','action'=>'show','id'=>$this->params['product_id']));
} else {

}
}

if (($product->hasOptions() || $product->hasUserInputFields()) && (!isset($this->params['options_shown']) || $this->params['options_shown']!= $product->id))
{

Expand Down
11 changes: 5 additions & 6 deletions framework/modules/ecommerce/products/datatypes/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ function addToCart($params, $orderid = null) {
if ($orderid == null) global $order;
else $order = new order($orderid);
//eDebug($this);
//eDebug($params,true);
$params['qty'] = isset($params['qty']) ? $params['qty'] : 1;
$params['quantity'] = isset($params['quantity']) ? $params['quantity'] : 1;
if (!isset($params['product_type'])) $params['product_type'] = 'product';

$params['error'] = '';
Expand All @@ -176,7 +175,7 @@ function addToCart($params, $orderid = null) {
if($orderItem->product_id == $this->id) $qCheck += $orderItem->quantity;
}
//}
$qty = $params['qty'];
$qty = $params['quantity'];
if (($this->quantity - $qCheck) < $qty) {
if ($this->availability_type == 2) {
flash('error', $this->title.' only has '.$this->quantity.' on hand. You can not add more than that to your cart.');
Expand All @@ -188,8 +187,8 @@ function addToCart($params, $orderid = null) {
if (($qty + $qCheck) < $this->minimum_order_quantity)
{
flash('message', $this->title.' has a minimum order quantity of '.$this->minimum_order_quantity.'. The quantity has been adjusted accordingly.');
$params['qty'] += $this->minimum_order_quantity - ($qty + $qCheck);
$qty = $params['qty'];
$params['quantity'] += $this->minimum_order_quantity - ($qty + $qCheck);
$qty = $params['quantity'];
}
}else
{
Expand Down Expand Up @@ -385,7 +384,7 @@ private function createOrderItem($product, $params, $user_input_info, $orderid)
eDebug($params);
eDebug($product->minimum_order_quantity);*/

$item->quantity += is_numeric($params['qty']) && $params['qty'] >= $product->minimum_order_quantity ? $params['qty'] : $product->minimum_order_quantity;
$item->quantity += is_numeric($params['quantity']) && $params['quantity'] >= $product->minimum_order_quantity ? $params['quantity'] : $product->minimum_order_quantity;
if ($item->quantity < 1 ) $item->quantity = 1;
// eDebug($item->quantity,true);
//eDebug($params);
Expand Down

0 comments on commit 27ea4aa

Please sign in to comment.