示例#1
0
 function addToCart($params)
 {
     global $order;
     expSession::set('params', $params);
     //get the configuration
     $cfg->mod = "ecomconfig";
     $cfg->src = "@globalstoresettings";
     $cfg->int = "";
     $config = new expConfig($cfg);
     $this->config = empty($catConfig->config) || @$catConfig->config['use_global'] == 1 ? $config->config : $catConfig->config;
     $min_amount = $this->config['minimum_gift_card_purchase'];
     $custom_message_product = $this->config['custom_message_product'];
     if (empty($params['product_id'])) {
         flash('error', gt("Please specify the style of the gift card you want to purchase."));
         expHistory::back();
     }
     if (empty($params['card_amount']) && empty($params['card_amount_txt'])) {
         flash('error', gt("You need to specify the card amount for the gift card."));
         expHistory::back();
     } else {
         // eDebug($params, true);
         $item = new orderitem($params);
         $sm = $order->getCurrentShippingMethod();
         $item->shippingmethods_id = $sm->id;
         if (isset($params['card_amount_txt'])) {
             $params['card_amount_txt'] = preg_replace("/[^0-9.]/", "", $params['card_amount_txt']);
         }
         if (!empty($params['card_amount_txt']) && $params['card_amount_txt'] > 0) {
             $item->products_price = preg_replace("/[^0-9.]/", "", $params['card_amount_txt']);
         } else {
             $item->products_price = preg_replace("/[^0-9.]/", "", $params['card_amount']);
         }
         if ($item->products_price < $min_amount) {
             flash('error', gt("The minimum amount of gift card is") . " " . $min_amount);
             expHistory::back();
         }
         $item->products_name = expCore::getCurrencySymbol() . $params['card_amount'] . ' ' . $this->title . " Style Gift Card";
         if (!empty($params['toname'])) {
             $ed['To'] = isset($params['toname']) ? $params['toname'] : '';
         }
         if (!empty($params['fromname'])) {
             $ed['From'] = isset($params['fromname']) ? $params['fromname'] : '';
         }
         if (!empty($params['msg'])) {
             $ed['Message'] = isset($params['msg']) ? $params['msg'] : '';
             $item->products_price += $custom_message_product;
             $item->products_name = $item->products_name . " (with message)";
         }
         $item->extra_data = serialize($ed);
         // we need to unset the orderitem's ID to force a new entry..other wise we will overwrite any
         // other giftcards in the cart already
         $item->id = null;
         $item->quantity = $this->getDefaultQuantity();
         $item->save();
         return true;
     }
 }
示例#2
0
 private function rebuildCart()
 {
     //group items by type and id
     //since we can have the same product in different items (options and quantity discount)
     //remove items and readd?
     global $order;
     //eDebug($order,true);
     $items = $order->orderitem;
     foreach ($order->orderitem as $item) {
         $item->delete();
     }
     $order->orderitem = array();
     $order->refresh();
     foreach ($items as $item) {
         for ($x = 1; $x <= $item->quantity; $x++) {
             $product = $item->product;
             $price = $product->getBasePrice();
             $basePrice = $price;
             $options = array();
             if (!empty($item->opts)) {
                 foreach ($item->opts as $opt) {
                     $cost = $opt[2] == '$' ? $opt[4] : $basePrice * ($opt[4] * 0.01);
                     $cost = $opt[3] == '+' ? $cost : $cost * -1;
                     $price += $cost;
                     $options[] = $opt;
                 }
             }
             $params['options'] = serialize($options);
             $params['products_price'] = $price;
             $params['product_id'] = $product->id;
             $params['product_type'] = $product->product_type;
             $newitem = new orderitem($params);
             //eDebug($item, true);
             $newitem->products_price = $price;
             $newitem->options = serialize($options);
             $sm = $order->getCurrentShippingMethod();
             $newitem->shippingmethods_id = $sm->id;
             $newitem->save();
             $order->refresh();
         }
     }
     $order->save();
     /*eDebug($items);
       
       
       $options = array();  
       foreach ($this->optiongroup as $og) {
           if ($og->required && empty($params['options'][$og->id][0])) {
               
               flash('error', $this->title.' '.gt('requires some options to be selected before you can add it to your cart.'));
               redirect_to(array('controller'=>store, 'action'=>'show', 'id'=>$this->id));
           }
           if (!empty($params['options'][$og->id])) {
               foreach ($params['options'][$og->id] as $opt_id) {
                   $selected_option = new option($opt_id);
                   $cost = $selected_option->modtype == '$' ? $selected_option->amount :  $this->getBasePrice() * ($selected_option->amount * .01);
                   $cost = $selected_option->updown == '+' ? $cost : $cost * -1;                      
                   $price += $cost;
                   $options[] = array($selected_option->id,$selected_option->title,$selected_option->modtype,$selected_option->updown,$selected_option->amount);
               }
           }
       }
       //die();
       // add the product to the cart.
       $params['options'] = serialize($options);
       $params['products_price'] = $price;
       $item = new orderitem($params);
       //eDebug($item, true);
       $item->products_price = $price;
       $item->options = serialize($options);
       
       $sm = $order->getCurrentShippingMethod();
       $item->shippingmethods_id = $sm->id;
       $item->save();                            */
     return true;
 }
示例#3
0
 public function countOrderitemsByShippingmethod($shippingmethod_id)
 {
     $orderitem = new orderitem(null, false, false);
     return $orderitem->find('count', 'orders_id=' . $this->id . " AND shippingmethods_id=" . $shippingmethod_id);
 }
示例#4
0
 function save_order_item()
 {
     $oi = new orderitem($this->params['id']);
     //eDebug($this->params);
     /*eDebug($oi);
       eDebug(expUnserialize($oi->options));
       eDebug(expUnserialize($oi->user_input_fields),true);*/
     $oi->products_price = $this->params['products_price'];
     $oi->quantity = $this->params['quantity'];
     $oi->products_name = $this->params['products_name'];
     if ($oi->product->parent_id != 0) {
         $oi->product = new product($oi->product->parent_id, true, false);
     } else {
         //reattach the product so we get the optoin fields and such
         $oi->product = new product($oi->product->id, true, false);
     }
     //eDebug($oi->product,true);
     foreach ($oi->product->optiongroup as $og) {
         $isOptionEmpty = true;
         if (!empty($this->params['options'][$og->id])) {
             foreach ($this->params['options'][$og->id] as $opt) {
                 if (!empty($opt)) {
                     $isOptionEmpty = false;
                 }
             }
         }
         if (!$isOptionEmpty) {
             foreach ($this->params['options'][$og->id] as $opt_id) {
                 $selected_option = new option($opt_id);
                 $cost = $selected_option->modtype == '$' ? $selected_option->amount : $this->getBasePrice() * ($selected_option->amount * 0.01);
                 $cost = $selected_option->updown == '+' ? $cost : $cost * -1;
                 $options[] = array($selected_option->id, $selected_option->title, $selected_option->modtype, $selected_option->updown, $selected_option->amount);
             }
         }
     }
     eDebug($this->params);
     //eDebug($oi,true);
     $user_input_info = array();
     //check user input fields
     //$this->user_input_fields = expUnserialize($this->user_input_fields);
     //eDebug($this,true);
     foreach ($oi->product->user_input_fields as $uifkey => $uif) {
         /*if ($uif['is_required'] || (!$uif['is_required'] && strlen($params['user_input_fields'][$uifkey]) > 0)) 
           {
               if (strlen($params['user_input_fields'][$uifkey]) < $uif['min_length'])
               {
                   //flash('error', 'test');    
                   //redirect_to(array('controller'=>cart, 'action'=>'displayForm', 'form'=>'addToCart', 'product_id'=>$this->id, 'product_type'=>$this->product_type));  
                   $params['error'] .= $uif['name'].' field has a minimum requirement of ' . $uif['min_length'] . ' characters.<br/>';
                   
               }else if (strlen($params['user_input_fields'][$uifkey]) > $uif['max_length'] && $uif['max_length'] > 0)
               {
                   //flash('error', );    
                   //redirect_to(array('controller'=>cart, 'action'=>'displayForm', 'form'=>'addToCart', 'product_id'=>$this->id, 'product_type'=>$this->product_type));      
                   $params['error'] .= $uif['name'].' field has a maximum requirement of ' . $uif['max_length'] . ' characters.<br/>';
               } 
           }*/
         $user_input_info[] = array($uif['name'] => $this->params['user_input_fields'][$uifkey]);
     }
     //eDebug($options);
     //eDebug($user_input_info,true);
     $oi->options = serialize($options);
     $oi->user_input_fields = serialize($user_input_info);
     //eDebug($oi);
     $oi->save();
     $oi->refresh();
     //eDebug($oi,true);
     $order = new order($oi->orders_id);
     $order->calculateGrandTotal();
     $s = array_pop($order->shippingmethods);
     eDebug($s);
     $sm = new shippingmethod($s->id);
     $shippingCalc = new shippingcalculator($sm->shippingcalculator_id);
     $calcName = $shippingCalc->calculator_name;
     $calculator = new $calcName($shippingCalc->id);
     $pricelist = $calculator->getRates($order);
     foreach ($pricelist as $rate) {
         if ($rate['id'] == $sm->option) {
             $sm->shipping_cost = $rate['cost'];
             break;
         }
     }
     $sm->save();
     $order->refresh();
     $order->calculateGrandTotal();
     $order->save();
     flashAndFlow('message', 'Order item updated and order totals recalculated.');
     redirect_to(array('controller' => 'order', 'action' => 'show', 'id' => $this->params['orderid']));
 }
示例#5
0
 function addToCart($params)
 {
     if (empty($params['dollar_amount'])) {
         return false;
     } else {
         $item = new orderitem($params);
         $item->products_price = preg_replace("/[^0-9.]/", "", $params['dollar_amount']);
         $product = new product($params['product_id']);
         $item->products_name = $params['dollar_amount'] . ' ' . $this->product_name . ' to ' . $product->title;
         // we need to unset the orderitem's ID to force a new entry..other wise we will overwrite any
         // other giftcards in the cart already
         $item->id = null;
         $item->quantity = $this->getDefaultQuantity();
         $item->save();
         return true;
     }
 }
示例#6
0
 function addToCart($params)
 {
     global $db, $order;
     if (isset($params['registrants'])) {
         // save the order item
         for ($x = 0; $x < count($params['registrants']); $x++) {
             $ed[$x]['name'] = $params['registrants'][$x];
             $ed[$x]['email'] = $params['registrant_emails'][$x];
             $ed[$x]['phone'] = $params['registrant_phones'][$x];
         }
         // if the item is in the cart already use it, if not we'll create a new one
         $item = $order->isItemInCart($params['product_id'], $params['product_type']);
         if (empty($item->id)) {
             $item = new orderitem($params);
         }
         // if we already have this event in our cart then we need to merge the registrants
         $registrants = array();
         if (!empty($item->extra_data)) {
             $registrants = expUnserialize($item->extra_data);
         }
         $registrants = array_merge($registrants, $ed);
         $item->quantity = count($registrants);
         $item->extra_data = serialize($registrants);
         $item->save();
         return true;
     } else {
         return false;
     }
 }
示例#7
0
 private function createOrderItem($product, $params, $user_input_info, $orderid)
 {
     //eDebug($params,true);
     global $db;
     if ($orderid == null) {
         global $order;
     } else {
         $order = new order($orderid);
     }
     $price = $product->getBasePrice();
     $options = array();
     foreach ($this->optiongroup as $og) {
         $isOptionEmpty = true;
         if (!empty($params['options'][$og->id])) {
             foreach ($params['options'][$og->id] as $opt) {
                 if (!empty($opt)) {
                     $isOptionEmpty = false;
                 }
             }
         }
         if (!$isOptionEmpty) {
             foreach ($params['options'][$og->id] as $opt_id) {
                 $selected_option = new option($opt_id);
                 $cost = $selected_option->modtype == '$' ? $selected_option->amount : $this->getBasePrice() * ($selected_option->amount * 0.01);
                 $cost = $selected_option->updown == '+' ? $cost : $cost * -1;
                 $price = $price + $cost;
                 $options[] = array($selected_option->id, $selected_option->title, $selected_option->modtype, $selected_option->updown, $selected_option->amount);
             }
         }
     }
     //eDebug($params,true);
     // add the product to the cart.
     if ($orderid != null) {
         if (empty($params['children'])) {
             $price = $params['products_price'];
         } else {
             $price = $params['prod-price'][$product->id];
         }
     }
     $params['product_id'] = $product->id;
     $params['options'] = serialize($options);
     $params['products_price'] = $price;
     $params['user_input_fields'] = serialize($user_input_info);
     $params['orderid'] = $orderid;
     /*$params['products_status'] = 
       $params['products_warehouse_location'] = 
       $params['products_model'] = $product->model;*/
     $item = new orderitem($params);
     //eDebug($item);
     $item->products_price = $price;
     /*eDebug($item->quantity);
       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;
     if ($item->quantity < 1) {
         $item->quantity = 1;
     }
     // eDebug($item->quantity,true);
     //eDebug($params);
     //eDebug($item, true);
     //eDebug($item, true);
     $item->options = serialize($options);
     $item->user_input_fields = $params['user_input_fields'];
     $item->products_status = $product->product_status->title;
     if ($product->parent_id == 0 || $product->warehouse_location != '') {
         //eDebug("here1",true);
         $item->products_warehouse_location = $product->warehouse_location;
     } else {
         $item->products_warehouse_location = $db->selectValue('product', 'warehouse_location', 'id=' . $product->parent_id);
     }
     $item->products_model = $product->model;
     $sm = $order->getCurrentShippingMethod();
     $item->shippingmethods_id = $sm->id;
     //eDebug($item,true);
     $item->save();
     return;
 }