Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once(APPLICATION_PATH . '/modules/default/models/Core.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Users.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Products.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Lcl.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Orders.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/OrderItems.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/ContainerSale.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Container.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/OrderContainer.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Container.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Option.php');
- require_once(APPLICATION_PATH . '/modules/default/models/DbTable/Harmonized_Code.php');
- require_once(APPLICATION_PATH . '/../library/My/simple_html_dom.php');
- class CheckoutController extends Zend_Controller_Action
- {
- public $month;
- private $mess;
- public function init() {
- if ($this->getRequest()->isXmlHttpRequest()) {
- Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
- $this->_helper->layout->disableLayout();
- }
- if(!$_SESSION['order'])
- $this->_helper->redirector('index', '');
- $this->month = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');
- }
- public function indexAction () {
- $this->view->order = $_SESSION['order'];
- $this->view->month = $this->month;
- $users = new Model_DbTable_Users();
- if(!empty($_SESSION['Logins']['user_id']))
- $this->view->user = $users->fetchRow('id=' . $users->getAdapter()->quote($_SESSION['Logins']['user_id']));
- if(!empty($this->mess))
- $this->view->mess = $this->mess;
- }
- public function processAction() {
- $req = $this->getRequest();
- if ($req->isPost()) {
- $fee = $this->_getParam('fee', 0);
- if($fee != 0){
- $additional_charges = str_replace('_', ' ', implode(", ", $fee));
- }else{
- $additional_charges = NULL;
- }
- $data = array(
- 'firstname' => $this->_getParam('firstname', 0),
- 'lastname' => $this->_getParam('lastname', 0),
- 'gender' => $this->_getParam('gender', 0),
- 'company' => $this->_getParam('company', 0),
- 'address_1' => $this->_getParam('address_1', 0),
- 'address_2' => $this->_getParam('address_2', 0),
- 'country' => $this->_getParam('country', 0),
- 'city' => $this->_getParam('city', 0),
- 'state' => $this->_getParam('state', 0),
- 'postal_code' => $this->_getParam('postal_code', 0),
- 'email' => $this->_getParam('email', 0),
- 'phone' => $this->_getParam('phone', 0),
- );
- if(empty($_SESSION['Logins']['user_id'])) {
- $data_register = $data;
- $data_register['username'] = $this->_getParam('username', 0);
- $data_register['password'] = $this->_getParam('password', 0);
- $data_register['confirm'] = $this->_getParam('confirm', 0);
- $data_register['role_id'] = $this->_getParam('role_id', 0);
- $users = new Model_DbTable_Users();
- $user_id = $users->register($data_register);
- $_SESSION['Logins']['user_id'] = $user_id;
- }
- else
- $user_id = $_SESSION['Logins']['user_id'];
- $billing = $this->_getParam('billing', 0);
- if($billing == 1) {
- $data = array(
- 'user_id' => $user_id,
- 'firstname' => $this->_getParam('sh_firstname', 0),
- 'lastname' => $this->_getParam('sh_lastname', 0),
- 'gender' => $this->_getParam('sh_gender', 0),
- 'company' => $this->_getParam('sh_company', 0),
- 'address_1' => $this->_getParam('sh_address_1', 0),
- 'address_2' => $this->_getParam('sh_address_2', 0),
- 'country' => $this->_getParam('sh_country', 0),
- 'city' => $this->_getParam('sh_city', 0),
- 'state' => $this->_getParam('sh_state', 0),
- 'postal_code' => $this->_getParam('sh_postal_code', 0),
- 'email' => $this->_getParam('sh_email', 0),
- 'phone' => $this->_getParam('sh_phone', 0),
- 'sum' => $this->_getParam('txt_total', 0),
- 'card' => $this->_getParam('card_number', 0),
- 'additional_charges' => $additional_charges,
- );
- }
- else {
- $data['user_id'] = $user_id;
- $data['sum'] = $this->_getParam('txt_total', 0);
- $data['card'] = $this->_getParam('card_number', 0);
- }
- $ship = $this->getshippingprice($data['postal_code'], $fee);
- $data['ship'] = $ship['shipp'];
- $a = new My_Authorizenet;
- $a->add_field('x_login', '73MxA6ue');
- $a->add_field('x_tran_key', '48FuHz62EfKx772w');
- //$a->add_field('x_password', 'CHANGE THIS TO YOUR PASSWORD');
- $a->add_field('x_version', '3.1');
- $a->add_field('x_type', 'AUTH_CAPTURE');
- $a->add_field('x_test_request', 'TRUE'); // Just a test transaction
- $a->add_field('x_relay_response', 'FALSE');
- $a->add_field('x_delim_data', 'TRUE');
- $a->add_field('x_delim_char', '|');
- $a->add_field('x_encap_char', '');
- $a->add_field('x_first_name', $data['firstname']);
- $a->add_field('x_last_name', $data['lastname']);
- $a->add_field('x_address', $data['address_1']);
- $a->add_field('x_city', $data['city']);
- $a->add_field('x_state', $data['state']);
- $a->add_field('x_zip', $data['postal_code']);
- $a->add_field('x_country', $data['country']);
- $a->add_field('x_email', $data['email']);
- $a->add_field('x_phone', $data['phone']);
- $a->add_field('x_method', 'CC');
- $a->add_field('x_card_num', $this->_getParam('card_number', 0)); // test successful visa 4007000000027
- $a->add_field('x_amount', $this->_getParam('txt_total', 0));
- $a->add_field('x_exp_date', $this->_getParam('expiration_month', 0).$this->_getParam('expiration_year', 0)); // march of 2008
- $a->add_field('x_card_code', $this->_getParam('code', 0)); // Card CAVV Security code
- $pay = $a->process();
- if($pay == 1) {
- $orders = new Model_DbTable_Orders();
- $order_id = $orders->add($data);
- $products = new Model_DbTable_Products();
- $orderitem = new Model_DbTable_OrderItems();
- $order_container = new Model_DbTable_OrderContainer();
- $container_sale = new Model_DbTable_ContainerSale();
- $container = new Model_DbTable_Container();
- $active_container = $container->getContainer();
- $container_id = $active_container->id;
- $lcl = new Model_DbTable_Lcl();
- foreach($_SESSION['order'] as $item) {
- $product = $products->getProduct($item);
- $product_id = $product->product_id;
- $p_price = $product->price;
- $lcl_id = $product->lcl_id;
- $data = array(
- 'order_id' => $order_id,
- 'product_id' => $product_id,
- 'price' => $p_price,
- );
- $orderitem->add($data);
- $products->sale($product_id);
- $square = $product->height_ft * $product->width_ft * $product->depth_ft;
- $order_containers = $order_container->getOrderItems($lcl_id);
- if(!empty($order_containers)){
- $i = 0;
- foreach ($order_containers as $value) {
- $i++;
- $square_all = $square + $value['filled'];
- if($square_all < $active_container->square){
- $full = 2;
- $next = 0;
- }elseif($square_all == $active_container->square){
- $full = 1;
- $next = 0;
- }else{
- $next = 1;
- }
- if($next == 0){
- $order_container->update(array(
- 'filled' => $square_all,
- 'full' => $full,
- ), $value['id']);
- $order_container_id = $value['id'];
- } else {
- $container_code = $lcl->getLcl($lcl_id)->port_code . '-' . rand(1, 999999999);
- if($square < $active_container->square){
- $full = 2;
- }else{
- $full = 1;
- }
- $order_container->add(array(
- 'lcl_id' => $lcl_id,
- 'container_code' => $container_code,
- 'container_id' => $active_container->id,
- 'filled' => $square,
- 'full' => $full,
- ));
- $order_container_id = $order_container->getAdapter()->lastInsertId();
- }
- }
- if($i == 0){
- $container_code = $lcl->getLcl($lcl_id)->port_code . '-' . rand(1, 999999999);
- if($square < $active_container->square){
- $full = 2;
- }else{
- $full = 1;
- }
- $order_container->add(array(
- 'lcl_id' => $lcl_id,
- 'container_code' => $container_code,
- 'container_id' => $active_container->id,
- 'filled' => $square,
- 'full' => $full,
- ));
- $order_container_id = $order_container->getAdapter()->lastInsertId();
- }
- if(!empty($order_container_id)){
- $container_sale->add(array(
- 'order_container_id' => $order_container_id,
- 'order_id' => $order_id,
- 'products_id' => $product->product_id,
- 'user_id' => $_SESSION['Logins']['user_id'],
- 'additional_charges' => $additional_charges,
- ));
- }
- }
- }
- $_SESSION['order'] = '';
- $this->_helper->redirector->gotoUrlAndExit('confirmation?id='.$order_id);
- }
- $this->mess = '<div id="featuredHeader"><h2>Error with Transaction</h2></div>';
- $this->mess .= '<br /><div>'.$a->get_response_reason_text().'<br /><br /><br /></div>';
- $this->indexAction();
- $this->_helper->viewRenderer->setNoController(true);
- $this->_helper->viewRenderer('checkout/index');
- /* switch ($a->process()) {
- case 1: // Successs
- echo "<b>Success:</b><br>";
- echo $a->get_response_reason_text();
- echo "<br><br>Details of the transaction are shown below...<br><br>";
- break;
- case 2: // Declined
- echo "<b>Payment Declined:</b><br>";
- echo $a->get_response_reason_text();
- echo "<br><br>Details of the transaction are shown below...<br><br>";
- break;
- case 3: // Error
- echo "<b>Error with Transaction:</b><br>";
- echo $a->get_response_reason_text();
- echo "<br><br>Details of the transaction are shown below...<br><br>";
- break;
- }
- */
- // The following two functions are for debugging and learning the behavior
- // of authorize.net's response codes. They output nice tables containing
- // the data passed to and recieved from the gateway.
- }
- }
- public function getshippingprice($zipcode, $fees) {
- $products = new Model_DbTable_Products();
- $users = new Model_DbTable_Users();
- $lcl = new Model_DbTable_Lcl();
- $option = new Model_DbTable_Option();
- $container = new Model_DbTable_Container();
- $harmonized_code = new Model_DbTable_Harmonized_Code();
- $active_comtainer = $container->getContainer();
- if($active_comtainer->length == 20){
- $a_comtainer = 'rates20';
- }else{
- $a_comtainer = 'rates40';
- }
- // $shippingvals = $this->getOption('shippingvals');
- $price = 0;
- $shipp_price = 0;
- $lcl_price = 0;
- $misc_charge = 0;
- $add_charge = 0;
- $customs_charge = 0;
- $lcl_arr = array();
- if(!empty($zipcode)) {
- foreach($_SESSION['order'] as $item) {
- $product = $products->getProduct($item);
- $from = $users->fetchRow('id=' . $users->getAdapter()->quote($product->user_id_fk));
- if(is_numeric($product->height_metric) && $product->height_metric > 0){
- $height = $product->height_metric;
- }else{
- $height = 0;
- }
- if(is_numeric($product->width_metric) && $product->width_metric > 0){
- $width = $product->width_metric;
- }else{
- $width = 0;
- }
- if(is_numeric($product->depth_metric) && $product->depth_metric > 0){
- $depth = $product->depth_metric;
- }else{
- $depth = 0;
- }
- if(!in_array($product->lcl_id, $lcl_arr)){
- array_push($lcl_arr, $product->lcl_id);
- $add_charge += $option->fetchRow("name = 'driver waiting fee'")->value;
- if($fees != 0){
- foreach ($fees as $fee){
- switch ($fee) {
- case 'residential_delivery':
- $add_charge += $option->fetchRow("name = 'residential delivery'")->value;
- break;
- case 'inside_delivery':
- $inside_delivery = $option->fetchRow("name = 'inside delivery fee'")->value;
- $inside_delivery_min = $option->fetchRow("name = 'inside delivery fee min'")->value;
- $inside_delivery_max = $option->fetchRow("name = 'inside delivery fee max'")->value;
- $inside = $product['weight'] / 100 * $inside_delivery;
- if($inside < $inside_delivery_min){
- $add_charge += $inside_delivery_min;
- }elseif ($inside > $inside_delivery_max) {
- $add_charge += $inside_delivery_max;
- }else{
- $add_charge += $inside;
- }
- break;
- case 'lift_gate':
- $add_charge += $option->fetchRow("name = 'lift gate surcharge'")->value;
- break;
- case 'delivery_notification':
- $add_charge += $option->fetchRow("name = 'delivery notification pricing'")->value;
- break;
- }
- }
- }
- }
- $square = $height * $width * $depth;
- $rate = new My_UPS;
- if($product['weight'] > 150){
- $shipp_price += $this->upsrate($option->fetchRow("name = 'US-ZIP'")->value, $zipcode, $product['weight'], $square);
- }else{
- $rate->upsProduct("GND"); // See upsProduct() function for codes
- $rate->origin($option->fetchRow("name = 'US-ZIP'")->value, "US"); // Use ISO country codes!
- $rate->dest($zipcode, "US"); // Use ISO country codes!
- $rate->rate("RDP"); // See the rate() function for codes
- $rate->container("CP"); // See the container() function for codes
- $rate->weight($product['weight']);
- $rate->rescom("RES"); // See the rescom() function for codes
- $shipp_price += $rate->getQuote();
- }
- $lcl_cbn = $lcl->getLcl($product->lcl_id);
- $cbn = $lcl_cbn->$a_comtainer / $active_comtainer->square_m;
- $lcl_price = ($square * $cbn) + $lcl_price;
- $harmonized = $harmonized_code->getCode($product);
- $customs_charge += round($rate->price($product->price, $harmonized, 1), 2);
- $price += $product->price;
- $misc_charge += $option->fetchRow("name = 'Picking-fee'")->value;
- if($product->weight > 70){
- $misc_charge += $option->fetchRow("name = 'Unloading-fee'")->value;
- }
- }
- $ofr_charge = round($lcl_price, 2);
- $domestic_charge = $shipp_price;
- $shipp_price_all = $ofr_charge + $add_charge + $misc_charge + $customs_charge + $domestic_charge;
- return array(
- 'ofr_charge' => $ofr_charge,
- 'add_charge' => $add_charge,
- 'misc_charge' => $misc_charge,
- 'customs_charge' => $customs_charge,
- 'domestic_charge' => $domestic_charge,
- 'shipp' => $shipp_price_all,
- 'price' => $price,
- 'total' => ($shipp_price_all + $price),
- );
- }
- else
- return 0;
- }
- public function loadshippingpriceAction() {
- $zipcode = $this->_getParam('zipcode', 0);
- $fee = $this->_getParam('fee', 0);
- $fees = explode(',', $fee);
- $result = $this->getshippingprice($zipcode, $fees);
- if(!empty($result))
- echo json_encode($result);
- }
- function upsrate($shipFromZip, $shipToZip, $weight, $freight, $shipmentDate = NULL ) {
- if(is_null($shipmentDate)){
- $shipmentDate = date("mdY");
- }
- $fr = round(($freight / 160), 2);
- if($fr < 50){
- $frclass = 50;
- }elseif($fr >= 50 && $fr > 55){
- $frclass = 55;
- }elseif($fr >= 55 && $fr > 60){
- $frclass = 60;
- }elseif($fr >= 60 && $fr > 65){
- $frclass = 65;
- }elseif($fr >= 60 && $fr > 70){
- $frclass = 70;
- }elseif($fr >= 70 && $fr > 77.5){
- $frclass = 77.5;
- }elseif($fr >= 77.5 && $fr > 85){
- $frclass = 85;
- }elseif($fr >= 77.5 && $fr > 85){
- $frclass = 85;
- }elseif($fr >= 85 && $fr > 92.5){
- $frclass = 92.5;
- }elseif($fr >= 92.5 && $fr > 100){
- $frclass = 100;
- }elseif($fr >= 100 && $fr > 110){
- $frclass = 110;
- }elseif($fr >= 110 && $fr > 125){
- $frclass = 125;
- }elseif($fr >= 125 && $fr > 150){
- $frclass = 150;
- }elseif($fr >= 150 && $fr > 175){
- $frclass = 175;
- }elseif($fr >= 150 && $fr > 175){
- $frclass = 175;
- }elseif($fr >= 175 && $fr > 200){
- $frclass = 200;
- }elseif($fr >= 200 && $fr > 250){
- $frclass = 250;
- }elseif($fr >= 250 && $fr > 300){
- $frclass = 300;
- }elseif($fr >= 300 && $fr > 400){
- $frclass = 400;
- }elseif($fr >= 400 && $fr > 500){
- $frclass = 500;
- }else{
- $frclass = 50;
- }
- $url = "https://wwwapps.ups.com/fctc/processLtlEntry?contractUser=false&loc=en_US&original_loc=en_US&shipFromCountry=US&shipFromZip=$shipFromZip&shipToCountry=US&shipToZip=$shipToZip&shipmentDate=$shipmentDate&domesticDiscount=&freightClass1=$frclass&weight1=$weight&submit_button_next=Next";
- $data = file_get_html($url);
- $res = $data->find('table.dataTable tr.odd td', 1)->plaintext;
- $re = explode('USD', $res);
- $r = str_replace(' ', '', $re[0]);
- $return = str_replace(' ', '', $r);
- return $return;
- }
- /**
- * sends contact email
- *
- * @return
- * @access public
- */
- public function addAction() {
- $id = $this->_getParam('id', 0);
- if(!empty($id)) {
- $data = $_SESSION['order'];
- $data[$id] = $id;
- $_SESSION['order'] = $data;
- $this->_helper->redirector('cart', '');
- }
- else
- $this->_helper->redirector('custom', '');
- }
- public function deleteAction() {
- $id = $this->_getParam('id', 0);
- $data = $_SESSION['order'];
- unset($data[$id]);
- $_SESSION['order'] = $data;
- }
- public function ajaxValidateFieldUserAction() {
- $users = new Model_DbTable_Users();
- $this->_helper->json(array(
- $this->_getParam('fieldId'),
- !$users->hasColumnValue($this->_getParam('fieldId'), $this->_getParam('fieldValue')),
- ));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement