Example #1
0
 function checkout()
 {
     global $user, $order;
     $cfg->mod = "cart";
     $cfg->src = "@globalcartsettings";
     $cfg->int = "";
     $config = new expConfig($cfg);
     $order->calculateGrandTotal();
     $order->validateDiscounts(array('controller' => 'cart', 'action' => 'checkout'));
     if (!expSession::get('customer-signup') && !$user->isLoggedin()) {
         expHistory::set('viewable', $this->params);
         flash('message', gt("Please select how you would like to continue with the checkout process."));
         expHistory::redirecto_login(makeLink(array('module' => 'cart', 'action' => 'checkout'), 'secure'));
     }
     if ($order->total < intval($config->config['min_order'])) {
         flashAndFlow('error', "Note: Thank you for your decision to purchase. However, our minimum order for merchandise is \$" . number_format($config->config['min_order'], 2, ".", ",") . ". Please increase your quantity or continue shopping.");
     }
     if (empty($order->orderitem)) {
         flashAndFlow('error', 'There are no items in your cart.');
     }
     $billing = new billing();
     //eDebug($billing,true);
     if (count($billing->available_calculators) < 1) {
         flashAndFlow('error', 'This store is not configured to allow checkouts yet.  Please try back soon.');
     }
     // set a flow waypoint
     expHistory::set('viewable', $this->params);
     //this validate the discount codes already applied to make sure they are still OK
     //if they are not it will remove them and redirect back to checkout w/ a message flash
     //$order->updateOrderDiscounts();
     //eDebug($order);
     // are there active discounts in the db?
     $discountCheck = new discounts();
     $discountsEnabled = $discountCheck->find('all', 'enabled=1');
     if (empty($discountsEnabled)) {
         // flag to hide the discount box
         assign_to_template(array('noactivediscounts' => '1'));
         $discounts = null;
     } else {
         // get all current discount codes that are valid and applied
         $discounts = $order->getOrderDiscounts();
     }
     //eDebug($discounts);
     /*if (count($discounts)>=0) {
     		    // Mockup code
     		    $order->totalBeforeDiscounts = $order->total; // reference to the origional total
     		    $order->total = $order->total*85/100; // to simulate 15%
     		    
     		} */
     // call each products checkout() callback & calculate total
     foreach ($order->orderitem as $item) {
         $product = new $item->product_type($item->product_id);
         $product->checkout();
     }
     // get the specials...this is just a stub function for now.
     $specials = $this->getSpecials();
     // get all the necessary addresses..shipping, billing, etc
     $address = new address();
     //$addresses_dd = $address->dropdownByUser($user->id);
     $shipAddress = $address->find('first', 'user_id=' . $user->id . ' AND is_shipping=1');
     if (empty($shipAddress) || !$user->isLoggedin()) {
         expSession::set('customer-signup', false);
         flash('message', gt('Step One: enter your primary address info now.') . '<br><br>' . gt('You may also optionally provide a password if you would like to return to our store at a later time to view your order history or make additional purchases.') . '<br><br>' . gt('If you need to add another billing or shipping address you will be able to do so on the following page.'));
         redirect_to(array('controller' => 'address', 'action' => 'edit'));
     }
     // get the shipping calculators and the shipping methods if we need them
     $shipping = new shipping();
     //$shipping->shippingmethod->setAddress($shipAddress);
     //FJD?
     //$shipping->getRates();
     assign_to_template(array('cartConfig' => $config->config, 'shipping' => $shipping, 'user' => $user, 'billing' => $billing, 'discounts' => $discounts, 'order' => $order, 'order_types' => $order->getOrderTypes(), 'default_order_type' => $order->getDefaultOrderType(), 'order_statuses' => $order->getOrderStatuses(), 'default_order_status' => $order->getDefaultOrderStatus(), 'sales_reps' => $order->getSalesReps()));
 }
Example #2
0
 public function calculateGrandTotal()
 {
     // calulate promo codes and group discounts
     //we need to tally up the cart, apply discounts, TAX that TOTAL somehow (different tax clases come into play), then add shipping
     //grab our discounts
     $cartDiscounts = $this->getOrderDiscounts();
     //reset totals
     $this->total_discounts = 0;
     $this->shipping_total = 0;
     $this->shipping_total_before_discounts = 0;
     $this->shippingDiscount = 0;
     $this->surcharge_total = 0;
     $this->subtotal = 0;
     $this->total = 0;
     $this->grand_total = 0;
     $this->tax = 0;
     $validateDiscountMessage = '';
     //eDebug($this->surcharge_total);
     //hate doing double loops, but we need to have the subtotal figured out already for
     //doing the straight dollar disoount calculations below
     for ($i = 0; $i < count($this->orderitem); $i++) {
         // figure out the amount of the discount
         /*if (!empty($this->product_discounts)) {
               $discount_amount = ($this->orderitem[$i]->products_price * ($this->product_discounts * .01));
               // change the price of the orderitem..this is needed for when we calculate tax below.
               $this->orderitem[$i]->products_price = $this->orderitem[$i]->products_price - $discount_amount;
               // keep a tally  of the total amount being subtracted by this discount.
               $this->total_discounts += $discount_amount;                
           }*/
         //$this->orderitem[$i]->products_price = $this->orderitem[$i]->getPriceWithOptions(); // * $this->orderitem[$i]->quantity;
         $this->orderitem[$i]->products_price_adjusted = $this->orderitem[$i]->products_price;
         //$this->orderitem[$i]->products_price_original = $this->orderitem[$i]->product->getPrice();
         $this->subtotal += $this->orderitem[$i]->products_price * $this->orderitem[$i]->quantity;
         $this->surcharge_total += $this->orderitem[$i]->product->getSurcharge() * $this->orderitem[$i]->quantity;
     }
     for ($i = 0; $i < count($this->orderitem); $i++) {
         //only allowing one discount for now, but in future we'll need to process
         //multiple and accomdate the "weight" and 'allow other discounts' type settings
         //this foreach will only fire once as of now, and will only hit on one or the other
         //TODO: We need to use produce_price_adjusted in the loops to accomodate for more than one disocunt
         //otherwise it's just resetting them now instead of adding them
         foreach ($cartDiscounts as $od) {
             //do not calculate invalid discounts, but don't remove either
             $discount = new discounts($od->discounts_id);
             /*$validateDiscountMessage = $discount->validateDiscount();
               if($validateDiscountMessage != '') break;*/
             //percentage discount
             if ($discount->action_type == 3) {
                 $discount_amount = round($this->orderitem[$i]->products_price * ($discount->discount_percent / 100), 2);
                 // change the price of the orderitem..this is needed for when we calculate tax below.
                 $this->orderitem[$i]->products_price_adjusted = $this->orderitem[$i]->products_price - $discount_amount;
                 // keep a tally  of the total amount being subtracted by this discount.
                 $this->total_discounts += $discount_amount * $this->orderitem[$i]->quantity;
             }
             //straight $$ discount
             if ($discount->action_type == 4) {
                 $this->total_discounts = $discount->discount_amount;
                 //what % of the order is this product with all it's quantity
                 $percentOfTotalOrder = $this->orderitem[$i]->products_price * $this->orderitem[$i]->quantity / $this->subtotal;
                 //figoure out how much that'll be and what each quanityt piece will bare
                 $discountAmountPerItem = round($percentOfTotalOrder * $discount->discount_amount / $this->orderitem[$i]->quantity, 2);
                 //$discount_amount = $this->orderitem[$i]->products_price * ($discount->discount_percent / 100);
                 // change the price of the orderitem..this is needed for when we calculate tax below.
                 $this->orderitem[$i]->products_price_adjusted = $this->orderitem[$i]->products_price - $discountAmountPerItem;
                 // keep a tally  of the total amount being subtracted by this discount.
                 //$this->total_discounts += $discountAmountPerItem * $this->orderitem[$i]->quantity;                    //eDebug($discountAmountPerItem);
             }
         }
         // calculate the tax for this product
         $taxclass = new taxclass($this->orderitem[$i]->product->tax_class_id);
         $this->orderitem[$i]->products_tax = $taxclass->getProductTax($this->orderitem[$i]);
         $this->tax += $this->orderitem[$i]->products_tax * $this->orderitem[$i]->quantity;
         //save out the order item
         $this->orderitem[$i]->save();
     }
     // add the "cart discounts" - percentage for sure, but straight can work also should be added after the final total is calculated,
     //including tax but not shipping
     // $this->updateOrderDiscounts();
     /*foreach ($cartDiscounts as $od)
       {
           $discount = new discounts($od->discounts_id); 
           if ($discount->action_type == 4)
           {                       
                $this->total_discounts += $discount->discount_amount;                           
           }                 
       }   */
     // calculate the shipping costs - need to check shipping discounts here in the future
     $estimate_shipping = false;
     if ($this->shipping_required) {
         $shippingmethods = $this->getShippingMethods();
         if (count($shippingmethods) > 0) {
             foreach ($shippingmethods as $sm_id) {
                 $method = new shippingmethod($sm_id, true);
                 if ($method->requiresShipping($this)) {
                     /*
                                             //need to implement handling
                                             $shippingCalc = new shippingcalculator($method->shippingcalculator_id);
                                             $calc = new $shippingCalc->calculator_name($method->shippingcalculator_id);
                                             eDebug($calc,true);*/
                     $this->shipping_total += $method->shipping_cost;
                     // + $method->calculator->getHandling();
                 }
             }
         } else {
             $estimate_shipping = true;
         }
     }
     $this->shipping_total_before_discounts = $this->shipping_total;
     if (isset($cartDiscounts)) {
         foreach ($cartDiscounts as $od) {
             $discount = new discounts($od->discounts_id);
             $this->shipping_total = $discount->calculateShippingTotal($this->shipping_total);
         }
     }
     $this->shippingDiscount = $this->shipping_total_before_discounts - $this->shipping_total;
     //check here to make sure we don't discount ourselves into oblivion
     $orderTotalPreDiscounts = $this->subtotal + $this->tax + $this->shipping_total;
     if ($this->total_discounts > $orderTotalPreDiscounts) {
         $this->total_discounts = $orderTotalPreDiscounts;
     }
     $this->total = $this->subtotal - $this->total_discounts;
     if ($estimate_shipping) {
         $this->shipping_total = shipping::estimateShipping($this);
     }
     // figure out which tax zones apply to this order.
     $this->taxzones = taxclass::getCartTaxZones($this);
     $this->grand_total = $this->subtotal - $this->total_discounts + $this->tax + $this->shipping_total + $this->surcharge_total;
     //if($validateDiscountMessage != '') flash('message',$validateDiscountMessage);
     //eDebug($this, true);
 }
Example #3
0
 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT      |
 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,   |
 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT        |
 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,   |
 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY   |
 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT     |
 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   |
 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    |
 |                                                                         |
 +-------------------------------------------------------------------------+
*/
include "../../include/session.php";
include "include/tables.php";
include "include/fields.php";
include "./include/discounts.php";
$thetable = new discounts($db, "tbld:455b8839-162b-3fcb-64b6-eeb946f873e1");
$therecord = $thetable->processAddEditPage();
if (isset($therecord["phpbmsStatus"])) {
    $statusmessage = $therecord["phpbmsStatus"];
}
$stats = $thetable->getTotals($therecord["id"]);
$pageTitle = "Discount / Promotion";
$phpbms->cssIncludes[] = "pages/discounts.css";
$phpbms->jsIncludes[] = "modules/bms/javascript/discount.js";
$phpbms->onload[] = "init();";
//Form Elements
//==============================================================
$theform = new phpbmsForm();
$theinput = new inputCheckbox("inactive", $therecord["inactive"]);
$theform->addField($theinput);
$theinput = new inputField("name", $therecord["name"], NULL, true, NULL, 32, 64);
 public function manage_promocodes()
 {
     expHistory::set('manageable', $this->params);
     $pc = new promocodes();
     $do = new discounts();
     $promo_codes = $pc->find('all');
     $discounts = $do->find('all');
     assign_to_template(array('promo_codes' => $promo_codes, 'discounts' => $discounts));
 }
Example #5
0
 function order_report()
 {
     // stub function. I'm sure eventually we can pull up exising reports to pre-populate our form.
     $os = new order_status();
     $oss = $os->find('all');
     $order_status = array();
     $order_status[-1] = '';
     foreach ($oss as $status) {
         $order_status[$status->id] = $status->title;
     }
     $ot = new order_type();
     $ots = $ot->find('all');
     $order_type = array();
     $order_type[-1] = '';
     foreach ($ots as $orderType) {
         $order_type[$orderType->id] = $orderType->title;
     }
     $dis = new discounts();
     $diss = $dis->find('all');
     $discounts = array();
     $discounts[-1] = '';
     foreach ($diss as $dkey => $discount) {
         $discounts[$discount->id] = $discount->coupon_code;
     }
     /*$geo = new geoRegion();
       $geos = $geo->find('all');        
       $states = array();
       $states[-1] = '';
       foreach ($geos as $skey=>$state)
       {
           $states[$skey] = $state->name;
       } */
     $payment_methods = billingmethod::$payment_types;
     $payment_methods[-1] = "";
     ksort($payment_methods);
     //array('-1'=>'', 'V'=>'Visa','MC'=>'Mastercard','D'=>'Discover','AMEX'=>'American Express','PP'=>'PayPal','GC'=>'Google Checkout','Other'=>'Other');
     //eDebug(mktime(0,0,0,(strftime("%m")-1),1,strftime("%Y")));
     $prev_month = strftime("%A, %d %B %Y", mktime(0, 0, 0, strftime("%m") - 1, 1, strftime("%Y")));
     //eDebug(strftime("%A, %d %B %Y", mktime(0,0,0,(strftime("%m")-1),1,strftime("%Y"))));
     $now_date = strftime("%A, %d %B %Y");
     $now_hour = strftime("%I");
     $now_min = strftime("%M");
     $now_ampm = strftime("%p");
     assign_to_template(array('prev_month' => $prev_month, 'now_date' => $now_date, 'now_hour' => $now_hour, 'now_min' => $now_min, 'now_ampm' => $now_ampm));
     assign_to_template(array('order_status' => $order_status));
     assign_to_template(array('discounts' => $discounts));
     //assign_to_template(array('states'=>$states));
     assign_to_template(array('order_type' => $order_type));
     assign_to_template(array('payment_methods' => $payment_methods));
 }