예제 #1
0
 public function calculateCost($session, $cartItems)
 {
     //Here is an example, lets say that the shipping cost is one dollar per shipped item
     //Also, there is an international fee of $20 that will apply if the shipping address is not in Canada
     $result = 20.0;
     foreach ($cartItems as $cartItem) {
         $result += $cartItem->getQuantity();
     }
     if (!@$_SESSION['authenticated_user']) {
         return $result;
     }
     $userId = @$_SESSION['authenticated_user']->getId();
     $userDetails = UserDetails::getUserDetailsBasedOnUserId($userId);
     $shippingAddress = $userDetails->getAddress('shipping_address');
     if ($shippingAddress->getCountryName() == "Canada") {
         $result -= 20.0;
     }
     return $result;
 }
예제 #2
0
파일: EComm.php 프로젝트: anas/feedstore
 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;
 }