Exemplo n.º 1
0
 public static function getForm()
 {
     $form = parent::getForm();
     $paypalHost = 'https://' . SiteConfig::get('Cart::PaypalHostName') . '/cgi-bin/webscr';
     $form->updateAttributes(array('action' => $paypalHost));
     $form->updateAttributes(array('onSubmit' => "return checkBeforeSendToPaypal()"));
     $form->setConstants(array('cmd' => '_cart'));
     $form->addElement('hidden', 'cmd');
     $form->setConstants(array('upload' => 1));
     $form->addElement('hidden', 'upload');
     //Set the ID of the customer making this order
     $form->setConstants(array('custom' => session_id()));
     $form->addElement('hidden', 'custom');
     $form->setConstants(array('currency_code' => "CAD"));
     $form->addElement('hidden', 'currency_code');
     $form->setConstants(array('business' => SiteConfig::get('Cart::PaypalBusinessEmailAddress')));
     $form->addElement('hidden', 'business');
     $form->setConstants(array('return' => "http://" . $_SERVER['HTTP_HOST'] . "/store/orderComplete"));
     $form->addElement('hidden', 'return');
     //		<input type="hidden" name="return" value="ordercomplete.php?req=success">
     $items = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId());
     $count = 0;
     foreach ($items as $item) {
         $form->setConstants(array('item_name_' . ++$count => $item->getProduct()->getName()));
         $form->addElement('hidden', 'item_name_' . $count);
         $form->setConstants(array('item_number_' . $count => $item->getProduct()->getModel()));
         $form->addElement('hidden', 'item_number_' . $count);
         $form->setConstants(array('amount_' . $count => round($item->getPrice(), 2)));
         $form->addElement('hidden', 'amount_' . $count);
         $form->setConstants(array('quantity_' . $count => $item->getQuantity()));
         $form->addElement('hidden', 'quantity_' . $count);
         //The tax will be passed as one value
         //$taxRate = CartTaxRate::getTaxRate($item->getProduct()->getTaxClass(), $_SESSION['cart_checkout']['address']['shipping_address'])->getRate();
         //$taxValue = $taxRate * $item->getPrice();//Do not multiply by the quantity because paypal does it automatically
         //$taxValue = ceil($taxValue);
         //$taxValue = $taxValue / 100;
         //$form->setConstants( array ( 'tax_' . $count => $taxValue ) );
         //$form->addElement( 'hidden', 'tax_' . $count );
         //Charge the shipping cost only for the first item because the shipping cost will apply on all the items
         $shippingCost = 0;
         if ($count == 1) {
             $shipping = @$_SESSION['cart_checkout']['shipping'];
             if ($shipping) {
                 $shippingCost = number_format($_SESSION['cart_checkout']['shipping']->getCost(), 2);
             }
             $shippingCost = ceil($shippingCost * 100) / 100;
         }
         $form->setConstants(array('shipping_' . $count => $shippingCost));
         $form->addElement('hidden', 'shipping_' . $count);
     }
     $temp = new Module_Cart();
     $form->setConstants(array('tax_cart' => $temp->getTax()));
     $form->addElement('hidden', 'tax_cart');
     //$form->setConstants( array ( 'shipping' => number_format($_SESSION['cart_checkout']['shipping']->getCost(), 2) ) );
     //$form->addElement( 'hidden', 'shipping' );
     $form->addElement('image', 'cart_submit', 'https://www.paypal.com/en_US/i/btn/x-click-but23.gif');
     return $form;
 }
Exemplo n.º 2
0
 public function validateOrder()
 {
     //The following function checks to ses if the user paid for what they ordered or not
     //First, make sure that the receiver is us:
     $this->log("Receiver is: " . $_POST["business"] . ", Our account is: " . $this->accountEmail);
     if ($_POST["business"] != $this->accountEmail) {
         $_SESSION['cart_checkout']['orderFailureReason'] = "The money was paid to another user";
         return false;
     }
     $sessionID = $_POST["custom"];
     //Switch to the user's session. To do so, first we have to close the currenct session with Paypal.
     session_write_close();
     session_id($sessionID);
     //Then we have to assign the user's session ID
     session_start();
     //Then we can start a new session.
     $this->log("The ID of the session is: " . $sessionID);
     $this->log("The ID of the customer is: " . $_SESSION['authenticated_user']->getId());
     $this->log("Amount: " . $_POST["mc_gross"] . ", " . $_POST["mc_currency"]);
     $cartitems = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId());
     //Calculate the total amount of the client's order
     $tmpModule = new Module_Cart();
     $totalAmount = $tmpModule->getTotal();
     /*
     $totalAmount = 0.00;
     $tax = 0.00;
     foreach ($cartitems as $item) {
     	$rate = CartTaxRate::getTaxRate($item->getProduct()->getTaxClass(), $_SESSION['cart_checkout']['address']['shipping_address'])->getRate();
     	$taxValue = $rate * ($item->getPrice() * $item->getQuantity());
     	$taxValue = ceil($taxValue);
     	$taxValue = $taxValue / 100;
     	$totalAmount += $item->getPrice() * $item->getQuantity() + $taxValue;
     }
     $shipping = @$_SESSION['cart_checkout']['shipping'];
     if ($shipping){
     	$shippingCost = $shipping->getCost();
     	$shippingCost = ceil($shippingCost * 100) / 100;
     	$totalAmount += $shippingCost;
     }
     $totalAmount = ceil($totalAmount * 100) / 100;//Account for numbers such as: 19.6421 such amount will be rounded to 19.65
     */
     //The currency of the client's order is always in Canadian Dollar. This needs to be tweaked so the admin will be able to set the currencies
     $currency = "CAD";
     $this->log("The order amount is: " . $totalAmount . ", " . $currency);
     //The reason why we're using the ceil function here is to account for the difference in calculating the taxes(if any)
     //For example, if paypal rounds the tax down (2.3487 becomes 2.34) and we round it up (2.3487 becomes 2.35), there should be no difference
     if (ceil($totalAmount) == ceil($_POST["mc_gross"]) && $currency == $_POST["mc_currency"]) {
         $this->log("The client has paid for what they ordered");
         return true;
     } else {
         $this->log("The client has NOT paid for what they ordered");
         $_SESSION['cart_checkout']['orderFailureReason'] = "The client has NOT paid for what they ordered";
         return false;
     }
 }
Exemplo n.º 3
0
 public static function canUserCheckout()
 {
     $canCheckout = array();
     if (isset($_SESSION['authenticated_user']) && $_SESSION['authenticated_user']->getId()) {
         $cartitems = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId());
     } else {
         $canCheckout['userNotLoggedIn'] = 1;
         $cartitems = CartBasket::getUserCartBaskets();
     }
     $minimumPayment = SiteConfig::get("Cart::minimumPayment");
     $totalAmount = 0.0;
     foreach ($cartitems as $item) {
         $totalAmount += $item->getPrice() * $item->getQuantity();
     }
     if ($totalAmount < $minimumPayment) {
         $canCheckout['paymentLessThanMinimum'] = 1;
         $canCheckout['minimumPayment'] = $minimumPayment;
     }
     if (!isset($_SESSION['cart_checkout']['address']['shipping_address']) || !@$_SESSION['cart_checkout']['address']['shipping_address']->getCity() || !@$_SESSION['cart_checkout']['address']['shipping_address']->getState() || !@$_SESSION['cart_checkout']['address']['shipping_address']->getCountry()) {
         $canCheckout['shippingAddressNotPresent'] = 1;
     }
     if (!isset($_SESSION['cart_checkout']['address']['billing_address']) || !@$_SESSION['cart_checkout']['address']['billing_address']->getCity() || !@$_SESSION['cart_checkout']['address']['billing_address']->getState() || !@$_SESSION['cart_checkout']['address']['billing_address']->getCountry()) {
         $canCheckout['billingAddressNotPresent'] = 1;
     }
     return $canCheckout;
 }
Exemplo n.º 4
0
 public function process($values = null)
 {
     //It seems that the parameter $values is not used at all
     //I gave it a default value of null.
     //Anas, 29, October, 2008
     $order = new CartOrder();
     $customer = $_SESSION['authenticated_user'];
     $billing_adr = $_SESSION['cart_checkout']['address']['billing_address'];
     $shipping_adr = $_SESSION['cart_checkout']['address']['shipping_address'];
     $payment = $_SESSION['cart_checkout']['payment'];
     $shipping = $_SESSION['cart_checkout']['shipping'];
     $order->setCustomer($customer->getId());
     $order->setCustomerName($customer->getName());
     $order->setCustomerAddress($billing_adr->getId());
     $order->setCustomerTelephone($customer->getPhone());
     $order->setCustomerEmail($customer->getEmail());
     $order->setBillingName($customer->getName());
     $order->setBillingAddress($billing_adr->getId());
     $order->setDeliveryName($customer->getName());
     $order->setDeliveryAddress($shipping_adr->getId());
     $order->setPaymentMethod($payment->getName());
     $order->setPaymentModuleCode($payment->getClass());
     $order->setShippingMethod($shipping->getName());
     $order->setShippingModuleCode($shipping->getClass());
     $order->setShippingCost($shipping->getCost());
     $order->setCurrency('CAD');
     $order->setCurrencyValue('1.000000');
     $order->setDeliveryDirections($_SESSION['cart_checkout']['delivery_direction']);
     $cartitems = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId());
     $subtotal = 0;
     $tax = 0;
     foreach ($cartitems as $item) {
         $subtotal += $item->getPrice() * $item->getQuantity();
         $taxclass = $item->getProduct()->getTaxClass();
         $taxrate = CartTaxRate::getTaxRate($taxclass, $shipping_adr)->getRate();
         $tax += $taxrate / 100 * ($item->getPrice() * $item->getQuantity());
     }
     $order->setSubTotal($subtotal);
     $order->setTax($tax);
     $order->setTotal($subtotal + $tax + $shipping->getCost());
     $order->setStatus(1);
     $order->setIp_address($_SERVER['REMOTE_ADDR']);
     $order->setDate_purchased(date('Y-m-d H:i:s'));
     $order->setPaypal_ipn_id(@$_REQUEST["txn_id"]);
     $order->save();
     foreach ($cartitems as $item) {
         $product = new CartOrderProduct();
         $product->setOrderId($order->getId());
         $product->setProduct($item->getProduct()->getId());
         $product->setModel($item->getProduct()->getModel());
         $product->setName($item->getProduct()->getName());
         $product->setPrice($item->getPrice());
         $product->setFinalPrice($item->getQuantity() * $item->getPrice());
         $product->setQuantity($item->getQuantity());
         $taxclass = $item->getProduct()->getTaxClass();
         $taxrate = CartTaxRate::getTaxRate($taxclass, $billing_adr)->getRate();
         $product->setTax($taxrate);
         $product->save();
         if ($item->getProduct()->getAttId()) {
             $product_atts = CartBasketAttribute::getCartBasketProductAttributes($item->getProduct()->getId() . ':' . $item->getProduct()->getAttId());
             foreach ($product_atts as $product_att) {
                 $att = new CartOrderProductAttribute();
                 $att->setOrderid($order->getId());
                 $att->setProductid($product->getId());
                 $option = new CartProductOption($product_att['products_options_id']);
                 // works
                 $att->setProducts_options($option->getName());
                 // works
                 $option_value = new CartProductOptionValue($product_att['products_options_value_id']);
                 $att->setProducts_options_values($option_value->getName());
                 $sql = 'select * from cart_products_attributes where options_id=' . $product_att['products_options_id'] . ' and ';
                 $sql .= 'options_values_id=' . $product_att['products_options_value_id'] . ' and ';
                 $sql .= 'products_id=' . $item->getProduct()->getId();
                 $r = Database::singleton()->query_fetch($sql);
                 $att->setOptions_values_price($r['options_values_price']);
                 $att->save();
             }
         }
     }
     $_SESSION['cart_checkout']['order'] = $order;
 }
Exemplo n.º 5
0
 public function getCost()
 {
     /*
      * The shipping cost is calculated as the following:
      * The pallet count is how many items can fit onto one "pallet".
      * We ship items by pallets and determine our delivery costs by how many pallets are shipped. 
      * If we're shipping 20 bags of product X and 40 bags of products Y where:
      * pallet count of X is 10
      * pallet count of Y is 5
      * That means that we are shipping: 2 pallets for X and 8 pallets for Y. Thus 10 pallets in total
      * 
      * The Shipping rates will be determined by the number of pallets each order makes up AND also by the total cost (before GST) for the order.
      * Freight charges:
      * $70/ pallet on orders up to $499
      * $60/pallet on orders $550 - $999
      * $50/pallet on orders +$1000
      */
     if (isset($_SESSION['authenticated_user'])) {
         $cartitems = CartBasket::getUserCartBaskets($_SESSION['authenticated_user']->getId());
     } else {
         $cartitems = CartBasket::getUserCartBaskets();
     }
     $totalAmount = 0.0;
     $palletCount = 0.0;
     foreach ($cartitems as $item) {
         $totalAmount += $item->getPrice() * $item->getQuantity();
         if ($item->getProduct()->getPalletCount() != 0) {
             $palletCount += $item->getQuantity() / $item->getProduct()->getPalletCount();
         } else {
             $palletCount += 0;
         }
     }
     $palletCount = ceil($palletCount);
     //Round up the number of pallets to an integer number
     if ($totalAmount >= 1000) {
         return SiteConfig::get("Cart::ShippingCostMoreThan1000") * $palletCount;
     } elseif ($totalAmount >= 500) {
         return SiteConfig::get("Cart::ShippingCostLessThan999") * $palletCount;
     } else {
         return SiteConfig::get("Cart::ShippingCostLessThan499") * $palletCount;
     }
 }