public static function _init()
 {
     if (!self::$_config) {
         $a = array("store_name" => "The Canteen", "realtime_inventory" => true, "global_discount" => false, "global_discount_rate" => "0", "global_discount_type" => false, "free_shipping" => false, "free_shipping_subtotal" => 0, "free_shipping_countries" => array("US"), "currencies" => array("USD", "GBP", "EUR", "CAD", "AUD", "BRL"), "user_currency" => array("GBP" => array("GB", "UK"), "EUR" => array("AD", "AT", "BE", "CY", "EE", "FI", "FR", "DE", "GR", "IE", "IT", "LU", "MT", "MC", "ME", "NL", "PT", "SM", "SK", "SI", "ES", "VA"), "CAD" => array("CA"), "AUD" => array("AU"), "BRL" => array("BR")), "gateway_account_id" => 3, "tax_regions" => array("US-CA" => 9.25), "shipping_codes" => array("03" => "Ground Shipment", "02" => "Second Day Air", "01" => "Next Day Air"));
         self::$_config = $a;
     }
 }
 public function getUserCurrency()
 {
     $cid = "USD";
     $geo = isset($_SERVER['GEOIP_COUNTRY_CODE']) ? $_SERVER['GEOIP_COUNTRY_CODE'] : "US";
     if (isset($_GET['currency_override'])) {
         $cid = $_GET['currency_override'];
     } else {
         if ($this->Session->check("UserCurrency")) {
             $cid = $this->Session->read("UserCurrency");
         } else {
             $cid = CanteenConfig::returnUserCurrencyId();
         }
     }
     $this->set("user_currency_id", $cid);
     return $cid;
 }
 /**
  * 
  * @param CanteenOrder $CanteenOrder
  * @param String $method charge | auth 
  * @return void
  */
 public function chargeOnlineOrder($CanteenOrder, $method = "charge")
 {
     $gateway_id = CanteenConfig::get("gateway_account_id");
     $possible_fraud = false;
     $trans = GatewayTransactionVO::formatCanteenOrder($CanteenOrder);
     //check geo country
     if ($_SERVER['GEOIP_COUNTRY_CODE'] != $CanteenOrder['BillingAddress']['country_code']) {
         $method = "auth";
         $possible_fraud = true;
     }
     $res = $this->GatewayTransaction->GatewayAccount->run($method, $gateway_id, $trans);
     //verb to update order status
     $verb = "declined";
     //if the charge succeeded
     if ($res) {
         switch (strtoupper($method)) {
             case "CHARGE":
                 $verb = "approved";
                 break;
             case "AUTH":
                 $verb = "authorized";
                 break;
         }
         unset($CanteenOrder['CardData']);
     }
     $this->create();
     $this->id = $CanteenOrder['CanteenOrder']['id'];
     $this->save(array("order_status" => $verb));
     if ($res) {
         //allocate inventory
         $_SERVER['FORCEMASTER'] = true;
         $this->processOrderInventory($CanteenOrder['CanteenOrder']['id']);
         $this->CanteenShippingRecord->createShipment($CanteenOrder['CanteenOrder']['id']);
         unset($_SERVER['FORCEMASTER']);
         //queue order email
         $this->EmailMessage->canteenOrderConfirmation($CanteenOrder);
         if ($possible_fraud) {
             $this->CanteenOrderNote->addHiddenNote(array("canteen_order_id" => $CanteenOrder['CanteenOrder']['id'], "message" => "Possible Fraud. Confirm Order With Customer"));
         }
     }
     return $res;
 }
 public function add()
 {
     if (count($this->request->data) > 0) {
         $this->fixPublishDate();
         $this->request->data['Tag'] = $this->CanteenProduct->Tag->parseTags($this->request->data['CanteenProduct']['tags']);
         if (empty($this->request->data['CanteenProduct']['uri'])) {
             $brand = $this->CanteenProduct->Brand->find("first", array("conditions" => array("Brand.id" => $this->request->data['CanteenProduct']['brand_id']), "contain" => array()));
             $ustr = $brand['Brand']['name'] . " " . $this->request->data['CanteenProduct']['name'] . " " . $this->request->data['CanteenProduct']['sub_title'];
             $this->request->data['CanteenProduct']['uri'] = Tools::safeUrl($ustr) . ".html";
         }
         $this->request->data['CanteenProduct']['display_weight'] = 99;
         $this->CanteenProduct->save($this->request->data);
         $new_id = $this->CanteenProduct->id;
         //add in all the product prices in the default config
         $curr = CanteenConfig::get("currencies");
         foreach ($curr as $c) {
             $this->CanteenProduct->CanteenProductPrice->create();
             $this->CanteenProduct->CanteenProductPrice->save(array("canteen_product_id" => $new_id, "currency_id" => $c));
         }
         return $this->flash("Product Added Successfully", "/canteen_products/edit/" . $new_id);
     } else {
         $this->request->data['CanteenProduct']['pub_date'] = date("Y-m-d", strtotime("+30 Day"));
         $this->request->data['CanteenProduct']['pub_time'] = "00:00";
     }
     $this->canteenProductSelects();
 }