Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:zuha/Ecommerce-Zuha-Cakephp-Plugin

  • Loading branch information...
commit 2a821bfbe576d717719b6dd5e1aa6bfc814aef0b 2 parents 3b1a6e6 + 791448f
Richard Kersey authored
Showing with 38 additions and 31 deletions.
  1. +4 −30 Controller/OrderItemsController.php
  2. +34 −1 Model/OrderItem.php
View
34 Controller/OrderItemsController.php
@@ -78,36 +78,10 @@ public function add($catalogItemId = null) {
$this->Session->setFlash(__($ret['msg'], true));
}
} else {
- /**
- * They are not logged in.
- * If Guest Checkout is enabled, they might have provided login credentials on the checkout page.
- */
- $guestCheckoutEnabled = (defined('__ORDERS_ENABLE_GUEST_CHECKOUT')) ? __ORDERS_ENABLE_GUEST_CHECKOUT : FALSE;
- if($guestCheckoutEnabled) {
- if(empty($this->request->data['User']['password'])) {
- // this is likely a new account, or a user that didn't fill out their password
- $this->request->data['User']['password'] = md5(rand().rand());
- App::uses('User', 'Users.Model');
- $User = new User();
- $User->add($this->request->data);
- $User->resetPassword($User->id);
- }
- $loginSuccess = $this->Auth->login($this->request->data);
- if($loginSuccess) {
- // run this function again to continue the checkout as normally done
- $this->add($catalogItemId);
- } else {
- // return them to the checkout to try again
- $this->redirect(array('plugin' => 'orders', 'controller' => 'order_transactions' , 'action' => 'checkout'));
- }
- } else {
- /**
- * If they are here, then they are not logged in and have not seen the checkout page yet
- */
- $this->_addToCookieCart($this->request->data);
- #$this->redirect($redirect);
- $this->redirect(array('plugin' => 'orders', 'controller' => 'order_transactions' , 'action' => 'checkout'));
- }
+ // If they are here, then they are not logged in and have not seen the checkout page yet
+ $this->_addToCookieCart($this->request->data);
+ $this->redirect($redirect);
+
}
}
View
35 Model/OrderItem.php
@@ -176,6 +176,8 @@ public function prepareCartData($userId = null, $userRoleId = null){
'CatalogItem.name',
'CatalogItem.model',
'CatalogItem.foreign_key',
+ 'CatalogItem.cart_min',
+ 'CatalogItem.cart_max',
),
),
),
@@ -200,9 +202,11 @@ public function prepareCartData($userId = null, $userRoleId = null){
public function cartExtras($orderItems = null) {
$orderItems = $this->mergeCartDuplicates($orderItems);
+ $orderItems = $this->restrictByCartLimit($orderItems);
+ #debug($orderItems); break;
$price = '';
$quantity = '';
- $i = 0;
+ $i = 0; /** @todo this $i doesn't seem necessary **/
if (!empty($orderItems)) : foreach ($orderItems as $orderItem) :
$price += $orderItem['OrderItem']['price'] * $orderItem['OrderItem']['quantity'];
$quantity += $orderItem['OrderItem']['quantity'];
@@ -214,6 +218,35 @@ public function cartExtras($orderItems = null) {
}
+ /**
+ * Take all orderItems and reduce their quantity to the min/max cart qty that was set.
+ *
+ * @param array $orderItems The array of orderItems.
+ * @return array Same array with adjusted quantities.
+ */
+ public function restrictByCartLimit($orderItems) {
+ if (!empty($orderItems)) {
+ #debug($orderItems);
+ foreach ($orderItems as $orderItem) :
+ if( $orderItem['OrderItem']['quantity'] > $orderItem['CatalogItem']['cart_max'] && $orderItem['CatalogItem']['cart_max']) {
+ $orderItem['OrderItem']['quantity'] = $orderItem['CatalogItem']['cart_max'];
+ /** @todo Probably put a flash message here somehow. */
+ }
+ if( $orderItem['OrderItem']['quantity'] < $orderItem['CatalogItem']['cart_min'] && $orderItem['CatalogItem']['cart_min']) {
+ $orderItem['OrderItem']['quantity'] = $orderItem['CatalogItem']['cart_min'];
+ /** @todo Probably put a flash message here somehow. */
+ }
+ $limitedOrderItems[] = $orderItem;
+ endforeach;
+ return $limitedOrderItems;
+
+ } else {
+ return $orderItems;
+ }
+
+ }
+
+
/**
* Reduce the orderItems to one instance per orderItem with an updated quantity.
*

0 comments on commit 2a821bf

Please sign in to comment.
Something went wrong with that request. Please try again.