Beispiel #1
0
 public function getShippingCost($sessionId = null, $cartItems = null)
 {
     $session = Session::getActiveSession($sessionId);
     $sessionId = $session->getId();
     if (!is_array($cartItems)) {
         $cartItems = CartItem::getAll($sessionId);
     }
     return $this->calculateCost($session, $cartItems);
 }
Beispiel #2
0
 public function getPaymentForm()
 {
     $form = new Form('payment_form', 'payment_form', '/Store/Payment');
     $paypalHost = 'https://' . $this->hostName . '/cgi-bin/webscr';
     $form->updateAttributes(array('action' => $paypalHost));
     $form->updateAttributes(array('onSubmit' => "return checkBeforePayment()"));
     $tid = @$_SESSION['ECommTID'];
     if ($tid) {
         $transaction = Transaction::getTransactionBasedOnTID($tid);
         $sessionId = $transaction->getSession();
         $session = Session::getActiveSession($sessionId);
         $cartItems = CartItem::getAll($sessionId);
         //$form->setConstants( array ( 'cmd' => '_cart' ) );
         $form->setConstants(array('cmd' => '_xclick'));
         $form->addElement('hidden', 'cmd');
         $form->setConstants(array('upload' => 1));
         $form->addElement('hidden', 'upload');
         //Set the ID of the transaction for this order
         $form->setConstants(array('custom' => $tid));
         $form->addElement('hidden', 'custom');
         $form->setConstants(array('currency_code' => SiteConfig::get("EComm::Currency")));
         $form->addElement('hidden', 'currency_code');
         $form->setConstants(array('business' => $this->accountEmail));
         $form->addElement('hidden', 'business');
         $form->setConstants(array('return' => "http://" . $_SERVER['HTTP_HOST'] . "/Store/IPN/&action=OrderComplete&tid={$tid}"));
         $form->addElement('hidden', 'return');
         $cartDetails = Module_EComm::getCartDetails($sessionId, $cartItems);
         $form->setConstants(array('amount' => $cartDetails["subTotal"]));
         $form->addElement('hidden', 'amount');
         $form->setConstants(array('shipping' => $cartDetails["shipping"]));
         $form->addElement('hidden', 'shipping');
         $form->setConstants(array('tax' => $cartDetails["tax"]));
         $form->addElement('hidden', 'tax');
     }
     $form->addElement('image', 'cart_submit', 'https://www.paypal.com/en_US/i/btn/x-click-but23.gif');
     return $form->display();
 }
Beispiel #3
0
 public static function canUserCheckOut($session = null, $cartDetails = null)
 {
     /*
      * The criteria are:
      * 1. The user is logged in
      * 2. The user has shipping address
      * 3. The user has billing address
      * 4. The user has a phone number
      * 5. The order amount is more than a particular limit
      * 6. The shipping class is defined
      * 7. The payment class is defined
      */
     if (!$session) {
         $session = Session::getActiveSession();
     }
     $sessionId = $session->getId();
     if (!$session->getUser()) {
         //1. The user is logged in
         return "User is not logged in";
     }
     $userDetails = UserDetails::getUserDetailsBasedOnUserId($session->getUser());
     $shippingAddress = $userDetails->getAddress('shipping_address');
     if (!$shippingAddress || !$shippingAddress->getStreetAddress() || !$shippingAddress->getCity() || !$shippingAddress->getPostalCode() || !$shippingAddress->getState() || !$shippingAddress->getCountry()) {
         return "Shipping address cannot be empty";
     }
     $billingAddress = $userDetails->getAddress('billing_address');
     if (!$billingAddress || !$billingAddress->getStreetAddress() || !$billingAddress->getCity() || !$billingAddress->getPostalCode() || !$billingAddress->getState() || !$billingAddress->getCountry()) {
         return "Billing address cannot be empty";
     }
     if (!$userDetails->getPhoneNumber()) {
         //4.The user has a phone number
         return "Phone number cannot be empty";
     }
     if (!$cartDetails) {
         $cartDetails = Module_EComm::getCartDetails();
     }
     if ($cartDetails["subTotal"] < SiteConfig::get("EComm::MinimumOrderValue")) {
         //5. The order amount is more than a particular limit
         return "You must buy at least " . SiteConfig::get("EComm::MinimumOrderValue");
     }
     if (!$session->getShippingClass()) {
         //6. The shipping class is defined
         return "You did not select your shipping option";
     }
     if (!$session->getPaymentClass()) {
         //7. The payment class is defined
         return "You did not select your payment option";
     }
     return 0;
 }