Esempio n. 1
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $current_user = SJB_UserManager::getCurrentUser();
     $action = SJB_Request::getVar('action', 'productList');
     $productSID = SJB_Request::getVar('product_sid', 0, 'default', 'int');
     $template = 'products.tpl';
     $availableProducts = array();
     $errors = array();
     switch ($action) {
         case 'productList':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $postingProductsOnly = SJB_Request::getVar('postingProductsOnly', false);
                 $availableProducts = SJB_ProductsManager::getProductsByUserGroupSID($current_user->getUserGroupSID(), $current_user->getSID());
                 $trialProduncts = $current_user->getTrialProductSIDByUserSID();
                 foreach ($availableProducts as $key => $availableProduct) {
                     if (in_array($availableProduct['sid'], $trialProduncts) || $postingProductsOnly && $availableProduct['product_type'] != "post_listings" && $availableProduct['product_type'] != "mixed_product") {
                         unset($availableProducts[$key]);
                     }
                 }
                 if ($postingProductsOnly) {
                     $tp->assign('postingProductsOnly', $postingProductsOnly);
                 }
             } elseif ($userGroupID = SJB_Request::getVar('userGroupID', false)) {
                 $userGroupSID = SJB_UserGroupManager::getUserGroupSIDByID($userGroupID);
                 $availableProducts = SJB_ProductsManager::getProductsByUserGroupSID($userGroupSID, 0);
             } else {
                 $availableProducts = SJB_ProductsManager::getAllActiveProducts();
             }
             foreach ($availableProducts as $key => $availableProductInfo) {
                 if (SJB_ProductsManager::isProductTrialAndAlreadyInCart($availableProductInfo, $current_user)) {
                     unset($availableProducts[$key]);
                     continue;
                 }
                 $availableProduct = new SJB_Product($availableProductInfo, $availableProductInfo['product_type']);
                 $availableProduct->setNumberOfListings(1);
                 $availableProducts[$key]['price'] = $availableProduct->getPrice();
                 if (isset($availableProducts[$key]['listing_type_sid'])) {
                     $availableProducts[$key]['listing_type_id'] = SJB_ListingTypeDBManager::getListingTypeIDBySID($availableProducts[$key]['listing_type_sid']);
                 }
             }
             SJB_Event::dispatch('RedefineTemplateName', $template, true);
             SJB_Event::dispatch('RedefineProductsDisplayInfo', $availableProducts, true);
             $tp->assign("account_activated", SJB_Request::getVar('account_activated', ''));
             $tp->assign("availableProducts", $availableProducts);
             break;
         case 'view_product_detail':
             $template = 'view_product_detail.tpl';
             if (!SJB_UserManager::isUserLoggedIn() || $current_user->mayChooseProduct($productSID, $errors)) {
                 $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
                 if (in_array($productInfo['product_type'], array('post_listings', 'mixed_product'))) {
                     $productInfo['listingTypeID'] = SJB_ListingTypeManager::getListingTypeIDBySID($productInfo['listing_type_sid']);
                 }
                 $event = SJB_Request::getVar('event', false);
                 if ($event) {
                     if ($productInfo) {
                         switch ($productInfo['product_type']) {
                             case 'banners':
                                 $params = $_REQUEST;
                                 if (empty($params['title'])) {
                                     $errors[] = "Banner Title is empty.";
                                 }
                                 if (empty($params['link'])) {
                                     $errors[] = "Banner link mismatched!";
                                 }
                                 if (empty($_FILES['image']['name'])) {
                                     $errors[] = "No file attached!";
                                 } elseif ($_FILES['image']['error']) {
                                     switch ($_FILES['image']['error']) {
                                         case '1':
                                             $errors[] = 'UPLOAD_ERR_INI_SIZE';
                                             break;
                                         case '2':
                                             $errors[] = 'UPLOAD_ERR_FORM_SIZE';
                                             break;
                                         case '3':
                                             $errors[] = 'UPLOAD_ERR_PARTIAL';
                                             break;
                                         case '4':
                                             $errors[] = 'UPLOAD_ERR_NO_FILE';
                                             break;
                                         default:
                                             $errors[] = 'NOT_UPLOAD_FILE';
                                             break;
                                     }
                                 } else {
                                     $imageInfo = @getimagesize($_FILES['image']['tmp_name']);
                                     if (!$imageInfo || $imageInfo['2'] < 1 && $imageInfo['2'] > 3) {
                                         $errors[] = 'Image format is not supported';
                                     } elseif (!empty($productInfo['width']) && $imageInfo[0] != $productInfo['width']) {
                                         $errors[] = "Your banner dimensions exceed the required size. Please upload an appropriate banner.";
                                     } elseif (!empty($productInfo['height']) && $imageInfo[1] != $productInfo['height']) {
                                         $errors[] = "Your banner dimensions exceed the required size. Please upload an appropriate banner.";
                                     }
                                 }
                                 if ($errors) {
                                     break;
                                 }
                                 //add banner
                                 $title = $params['title'];
                                 $link = $params['link'];
                                 $expr = preg_match("/(http:\\/\\/)/", $link, $matches);
                                 if ($expr != true) {
                                     $link = "http://" . $link;
                                 }
                                 $filesDir = SJB_System::getSystemSettings('FILES_DIR');
                                 $ext = preg_match("|\\.(\\w{3})\\b|u", $_FILES['image']['name'], $arr);
                                 $fileName = preg_replace("|\\.(\\w{3})\\b|u", "", $_FILES['image']['name']);
                                 $hashName = md5(time() * $_FILES['image']['size']) . "_" . $fileName;
                                 $bannerFilePath = $filesDir . "banners/" . $hashName . "." . $arr[1];
                                 $copy = move_uploaded_file($_FILES['image']['tmp_name'], $bannerFilePath);
                                 if (!$copy) {
                                     $errors[] = 'Cannot copy file from TMP dir to Banners Dir';
                                     break;
                                 }
                                 if ($_FILES['image']['type'] != 'application/x-shockwave-flash') {
                                     $bannerInfo = getimagesize($bannerFilePath);
                                     if ($productInfo['width'] != '' && $productInfo['height'] != '') {
                                         $sx = $productInfo['width'];
                                         $sy = $productInfo['height'];
                                     } else {
                                         $sx = $bannerInfo[0];
                                         $sy = $bannerInfo[1];
                                     }
                                     $type = $bannerInfo['mime'];
                                 } else {
                                     if ($productInfo['width'] == '' || $productInfo['height'] == '') {
                                         $errors[] = 'Your banner dimensions exceed the required size. Please upload an appropriate banner.';
                                         break;
                                     }
                                     $sx = $productInfo['width'];
                                     $sy = $productInfo['height'];
                                     $type = $_FILES['image']['type'];
                                 }
                                 $active = 0;
                                 $group = $productInfo['banner_group_sid'];
                                 $params['bannerFilePath'] = "/" . str_replace("../", "/", str_replace(SJB_BASE_DIR, '', $bannerFilePath));
                                 $params['openBannerIn'] = '';
                                 $params['bannerType'] = 'file';
                                 $params['code'] = '';
                                 $params['title'] = $title;
                                 $params['link'] = $link;
                                 $params['type'] = $type;
                                 $params['sx'] = $sx;
                                 $params['sy'] = $sy;
                                 $params['banner_group_sid'] = $group;
                                 $productInfo['banner_info'] = $params;
                                 break;
                         }
                         if (!$errors) {
                             $numberOfListings = SJB_Request::getVar('number_of_listings');
                             $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
                             if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based' && $numberOfListings) {
                                 $productInfo['number_of_listings'] = $numberOfListings;
                                 $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                                 $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                                 $productObj->setNumberOfListings($number_of_listings);
                                 $productInfo['price'] = $productObj->getPrice();
                             }
                             if (SJB_UserManager::isUserLoggedIn()) {
                                 SJB_ShoppingCart::addToShoppingCart($productInfo, $current_user->getSID());
                             } else {
                                 if (isset($_SESSION['products'])) {
                                     foreach ($_SESSION['products'] as $addedProduct) {
                                         $addedProductInfo = unserialize($addedProduct['product_info']);
                                         if ($addedProductInfo['user_group_sid'] != $productInfo['user_group_sid']) {
                                             $errors[] = 'You are trying to add products of different User Groups in your Shopping Cart. You сan add only products belonging to one User Group. If you want to add this product in the Shopping Cart please go back to the Shopping Cart and remove products of other User Groups.';
                                             break;
                                         }
                                     }
                                 }
                                 if (!$errors) {
                                     $id = time();
                                     $_SESSION['products'][$id]['product_info'] = serialize($productInfo);
                                     $_SESSION['products'][$id]['sid'] = $id;
                                     $_SESSION['products'][$id]['user_sid'] = 0;
                                 }
                             }
                             if (!$errors) {
                                 SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
                             }
                         }
                     }
                 }
                 if (!empty($productInfo['expiration_period']) && !is_numeric($productInfo['expiration_period'])) {
                     $productInfo['period'] = ucwords($productInfo['expiration_period']);
                 } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based' && !empty($productInfo['volume_based_pricing'])) {
                     $volumeBasedPricing = $productInfo['volume_based_pricing'];
                     $price = array();
                     $firstPrice = 0;
                     if (!empty($volumeBasedPricing['listings_range_from'])) {
                         for ($i = 1; $i <= count($volumeBasedPricing['listings_range_from']); $i++) {
                             if ($volumeBasedPricing['listings_range_from'][$i] == $volumeBasedPricing['listings_range_to'][$i]) {
                                 $price[$i]['range']['from'] = $volumeBasedPricing['listings_range_from'][$i];
                             } else {
                                 $price[$i]['range']['from'] = $volumeBasedPricing['listings_range_from'][$i];
                                 $price[$i]['range']['to'] = $volumeBasedPricing['listings_range_to'][$i];
                             }
                             $price[$i]['price'] = $volumeBasedPricing['price_per_unit'][$i];
                             if ($i > 1 && $firstPrice > $volumeBasedPricing['price_per_unit'][$i]) {
                                 $price[$i]['savings'] = round(100 - 100 / $firstPrice * $volumeBasedPricing['price_per_unit'][$i]);
                             } else {
                                 $firstPrice = $volumeBasedPricing['price_per_unit'][$i];
                             }
                         }
                     }
                     $productInfo['volume_based_pricing'] = $price;
                     $minListings = min($volumeBasedPricing['listings_range_from']);
                     $maxListings = max($volumeBasedPricing['listings_range_to']);
                     $countListings = array();
                     for ($i = $minListings; $i <= $maxListings; $i++) {
                         $countListings[] = $i;
                     }
                     $productInfo['count_listings'] = $countListings;
                 } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                     $productInfo['fixed_period'] = 1;
                 }
                 if ($productInfo['product_type'] == 'banners') {
                     $params = $_REQUEST;
                     $bannersObj = new SJB_Banners();
                     $banner_fields = $bannersObj->getBannersMeta();
                     foreach ($banner_fields as $key => $banner_field) {
                         $banner_fields[$banner_field['id']] = $banner_field;
                         if (!empty($params[$banner_field['id']])) {
                             $banner_fields[$banner_field['id']]['value'] = $params[$banner_field['id']];
                         }
                         unset($banner_fields[$key]);
                     }
                     if (!empty($params['errors'])) {
                         $tp->assign("errors", $params['errors']);
                     }
                     $tp->assign("banner_fields", $banner_fields);
                 }
                 $userGroupID = SJB_UserGroupDBManager::getUserGroupIDBySID($productInfo['user_group_sid']);
                 $tp->assign('productInfo', $productInfo);
                 $tp->assign('userGroupID', $userGroupID);
                 $tp->assign('productSID', $productSID);
                 $tp->assign('mayChooseProduct', true);
             }
             $tp->assign('errors', $errors);
             break;
     }
     $tp->display($template);
 }
Esempio n. 2
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $currentUser = SJB_UserManager::getCurrentUser();
     $action = SJB_Request::getVar('action', false);
     $error = SJB_Request::getVar('error', false);
     $applyPromoCode = SJB_Request::getVar('applyPromoCode', false);
     $action = $applyPromoCode ? 'applyPromoCode' : $action;
     $numberOfListings = SJB_Request::getVar('number_of_listings');
     $productInfo = null;
     $errors = array();
     switch ($action) {
         case 'delete':
             $itemSID = SJB_Request::getVar('item_sid', 0, false, 'int');
             if (SJB_UserManager::isUserLoggedIn()) {
                 if (SJB_Settings::getSettingByName('allow_to_post_before_checkout') == true) {
                     $this->findCheckoutedListingsByProduct($itemSID, $currentUser->getSID());
                 }
                 SJB_ShoppingCart::deleteItemFromCartBySID($itemSID, $currentUser->getSID());
             } else {
                 $products = SJB_Session::getValue('products');
                 if (!empty($products[$itemSID])) {
                     unset($products[$itemSID]);
                     SJB_Session::setValue('products', $products);
                 }
             }
             break;
         case 'checkout':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $products = SJB_Session::getValue('products');
                 $products = $products ? $products : array();
                 $trialProduct = false;
                 foreach ($products as $product) {
                     if (!empty($product['product_info'])) {
                         $productInfo = unserialize($product['product_info']);
                         if ($currentUser->getUserGroupSID() != $productInfo['user_group_sid']) {
                             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=user_group");
                         } elseif (in_array($productInfo['sid'], $currentUser->getTrialProductSIDByUserSID())) {
                             $trialProduct = true;
                         } else {
                             $product = new SJB_Product($productInfo, $productInfo['product_type']);
                             $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                             $product->setNumberOfListings($number_of_listings);
                             $productInfo['price'] = $product->getPrice();
                             SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUser->getSID());
                         }
                     }
                 }
                 SJB_Session::unsetValue('products');
                 if ($trialProduct) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=trial_product");
                 } elseif ($products) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/");
                 }
                 $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
                 if (empty($products)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/my-account/");
                 }
                 $isRecurring = false;
                 $subTotal = 0;
                 foreach ($products as $key => $product) {
                     $productInfo = unserialize($product['product_info']);
                     if (!empty($productInfo['recurring'])) {
                         $isRecurring = true;
                     }
                     if (!empty($productInfo['pricing_type']) == 'volume_based' && isset($numberOfListings[$productInfo['sid']][$product['sid']])) {
                         $productInfo['number_of_listings'] = $numberOfListings[$productInfo['sid']][$product['sid']];
                         $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                         $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
                         $productObj->setNumberOfListings($number_of_listings);
                         $productInfo['price'] = $productObj->getPrice();
                         if (!empty($productInfo['code_info'])) {
                             SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $productInfo['code_info']);
                         }
                         SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                     }
                     $subTotal += $productInfo['price'];
                     $products[$key] = $productInfo;
                     $products[$key]['item_sid'] = $product['sid'];
                     $products[$key]['product_info'] = serialize($productInfo);
                 }
                 $index = 1;
                 $items = array();
                 $codeInfo = array();
                 if ($isRecurring) {
                     $tp->assign('confirmation', 1);
                     $tp->assign('sub_total_price', $subTotal);
                 } else {
                     foreach ($products as $product) {
                         $product_info = unserialize($product['product_info']);
                         SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product, $product['code_info']);
                         $qty = !empty($product_info['number_of_listings']) ? $product_info['number_of_listings'] : null;
                         $items['products'][$index] = $product_info['sid'];
                         if ($qty > 0) {
                             $items['price'][$index] = round($product['price'] / $qty, 2);
                         } else {
                             $items['price'][$index] = round($product['price'], 2);
                         }
                         $items['amount'][$index] = $product['price'];
                         $items['qty'][$index] = $qty;
                         if (isset($product['custom_item'])) {
                             $items['custom_item'][$index] = $product['custom_item'];
                         } else {
                             $items['custom_item'][$index] = "";
                         }
                         if (isset($product['custom_info'])) {
                             $items['custom_info'][$index] = $product['custom_info'];
                         } else {
                             $items['custom_info'][$index]['shoppingCartRecord'] = $product['item_sid'];
                         }
                         if ($product_info['product_type'] == 'banners' && !empty($product_info['banner_info'])) {
                             $items['custom_info'][$index]['banner_info'] = $product_info['banner_info'];
                         }
                         $index++;
                         SJB_PromotionsManager::preparePromoCodeInfoByProductPromoCodeInfo($product_info, $codeInfo);
                     }
                     $subUserInfo = $currentUser->getSubuserInfo();
                     $userSID = isset($subUserInfo['sid']) ? $subUserInfo['sid'] : $currentUser->getSID();
                     $invoiceSID = SJB_InvoiceManager::generateInvoice($items, $userSID, $subTotal, SJB_System::getSystemSettings('SITE_URL') . "/create-contract/");
                     SJB_PromotionsManager::addCodeToHistory($codeInfo, $invoiceSID, $userSID);
                     if ($subTotal <= 0) {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/create-contract/?invoice_sid=' . $invoiceSID);
                     } else {
                         SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/payment-page/?invoice_sid=" . $invoiceSID);
                     }
                 }
             }
             break;
         case 'applyPromoCode':
             $promotionCode = SJB_Request::getVar('promotion_code', false);
             if ($promotionCode) {
                 if (SJB_UserManager::isUserLoggedIn()) {
                     $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
                 } else {
                     $products = SJB_Session::getValue('products');
                     $products = $products ? $products : array();
                     krsort($products);
                 }
                 $allowShoppingItems = array();
                 $productSIDs = array();
                 foreach ($products as $product) {
                     $productInfo = unserialize($product['product_info']);
                     if (!isset($productInfo['code_info'])) {
                         if (isset($productInfo['custom_info'])) {
                             $allowShoppingItems[] = $product['sid'];
                             $productSIDs[] = $productInfo['custom_info']['productSid'];
                         } else {
                             $allowShoppingItems[] = $product['sid'];
                             $productSIDs[] = $productInfo['sid'];
                         }
                     } else {
                         $appliedPromoCode = $productInfo['code_info'];
                     }
                 }
                 if ($codeInfo = SJB_PromotionsManager::checkCode($promotionCode, $productSIDs)) {
                     $productSIDs = $codeInfo['product_sid'] ? explode(',', $codeInfo['product_sid']) : false;
                     $appliedProducts = array();
                     $codeValid = false;
                     foreach ($products as $key => $product) {
                         $productInfo = unserialize($product['product_info']);
                         if ($productInfo['sid'] != '-1') {
                             $productSid = $productInfo['sid'];
                         } else {
                             $productSid = $productInfo['custom_info']['productSid'];
                         }
                         if ($productSIDs && in_array($productSid, $productSIDs) && $allowShoppingItems && in_array($product['sid'], $allowShoppingItems)) {
                             $currentUsesCount = SJB_PromotionsManager::getUsesCodeBySID($codeInfo['sid']);
                             if ($codeInfo['maximum_uses'] != 0 && $codeInfo['maximum_uses'] > $currentUsesCount || $codeInfo['maximum_uses'] == 0) {
                                 $codeValid = true;
                                 SJB_PromotionsManager::applyPromoCodeToProduct($productInfo, $codeInfo);
                                 $appliedProducts[] = $productInfo;
                                 if (SJB_UserManager::isUserLoggedIn()) {
                                     SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                                 } else {
                                     $products[$key]['product_info'] = serialize($productInfo);
                                     SJB_Session::setValue('products', $products);
                                 }
                             }
                         }
                     }
                     if (!$codeValid) {
                         $errors['NOT_VALID'] = 'Invalid promotion code';
                         unset($promotionCode);
                     }
                     $tp->assign('applied_products', $appliedProducts);
                     $tp->assign('code_info', $codeInfo);
                 } else {
                     $errors['NOT_VALID'] = 'Invalid promotion code';
                 }
                 if (isset($promotionCode) && isset($appliedPromoCode)) {
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/');
                 }
             } else {
                 $errors['EMPTY_VALUE'] = 'Promotion code';
             }
             break;
         case 'deletePromoCode':
             if (SJB_UserManager::isUserLoggedIn()) {
                 $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
             } else {
                 $products = SJB_Session::getValue('products');
                 $products = $products ? $products : array();
                 krsort($products);
             }
             foreach ($products as $key => $product) {
                 $productInfo = unserialize($product['product_info']);
                 SJB_PromotionsManager::removePromoCodeFromProduct($productInfo);
                 if (SJB_UserManager::isUserLoggedIn()) {
                     $numberOfListings = is_array($numberOfListings) ? array_pop($numberOfListings) : false;
                     if (is_array($numberOfListings)) {
                         foreach ($numberOfListings as $listingSid => $listingsCount) {
                             if ($listingSid == $product['sid']) {
                                 $productInfo['number_of_listings'] = $listingsCount;
                             }
                         }
                     }
                     SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
                 } else {
                     $products[$key]['product_info'] = serialize($productInfo);
                     SJB_Session::setValue('products', $products);
                 }
             }
             break;
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
         // To display products in shopping cart after user has been registered from shopping cart page
         if (empty($products)) {
             $products = SJB_Session::getValue('products');
             $products = $products ? $products : array();
         }
     } else {
         $products = SJB_Session::getValue('products');
         $products = $products ? $products : array();
         krsort($products);
     }
     $allowShoppingItems = array();
     foreach ($products as $product) {
         $productInfo = unserialize($product['product_info']);
         if (!empty($productInfo['code_info'])) {
             $promotionCode = $productInfo['code_info']['code'];
             $promotionCodeInfo = $productInfo['code_info'];
         } else {
             $allowShoppingItems[] = $product['sid'];
         }
     }
     $promotionCode = isset($promotionCode) ? $promotionCode : '';
     $totalPrice = 0;
     $discountTotalAmount = 0;
     $numberOfListings = SJB_Request::getVar('number_of_listings', false);
     foreach ($products as $key => $product) {
         $productInfo = unserialize($product['product_info']);
         if ($allowShoppingItems && in_array($product['sid'], $allowShoppingItems)) {
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             if (SJB_UserManager::isUserLoggedIn()) {
                 SJB_ShoppingCart::updateItemBySID($product['sid'], $productInfo);
             } else {
                 $products[$key]['product_info'] = serialize($productInfo);
             }
         }
         if ($numberOfListings && array_key_exists('number_of_listings', $productInfo) && array_key_exists($productInfo['sid'], $numberOfListings)) {
             $productInfo['number_of_listings'] = $numberOfListings[$productInfo['sid']][$product['sid']];
         }
         $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
         $productExtraInfo = unserialize($productInfo['serialized_extra_info']);
         if (!empty($productInfo['expiration_period']) && !is_numeric($productInfo['expiration_period'])) {
             $productInfo['primaryPrice'] = $productExtraInfo['price'];
             $productInfo['period'] = ucwords($productInfo['expiration_period']);
         } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
             $volumeBasedPricing = $productInfo['volume_based_pricing'];
             $number_of_listings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 1;
             $productObj->setNumberOfListings($number_of_listings);
             $productInfo['price'] = $productObj->getPrice();
             $productInfo['primaryPrice'] = $productObj->getPrice();
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             $minListings = min($volumeBasedPricing['listings_range_from']);
             $maxListings = max($volumeBasedPricing['listings_range_to']);
             $countListings = array();
             for ($i = $minListings; $i <= $maxListings; $i++) {
                 $countListings[$i]['number_of_listings'] = $i;
                 for ($j = 1; $j <= count($volumeBasedPricing['listings_range_from']); $j++) {
                     if ($i >= $volumeBasedPricing['listings_range_from'][$j] && $i <= $volumeBasedPricing['listings_range_to'][$j]) {
                         $countListings[$i]['price'] = $volumeBasedPricing['price_per_unit'][$j] * $i;
                         $countListings[$i]['primaryPrice'] = $volumeBasedPricing['price_per_unit'][$j] * $i;
                         if (!empty($productInfo['code_info']['type'])) {
                             switch ($productInfo['code_info']['type']) {
                                 case 'percentage':
                                     $countListings[$i]['price'] = round($countListings[$i]['price'] - $countListings[$i]['primaryPrice'] / 100 * $productInfo['code_info']['discount'], 2);
                                     $countListings[$i]['percentPromoAmount'] = round($countListings[$i]['primaryPrice'] - $countListings[$i]['price'], 2);
                                     $countListings[$i]['percentPromoCode'] = $productInfo['code_info']['code'];
                                     break;
                                 case 'fixed':
                                     $countListings[$i]['price'] = round($countListings[$i]['price'] - $productInfo['code_info']['discount'], 2);
                                     break;
                             }
                         }
                     }
                 }
             }
             $productInfo['count_listings'] = $countListings;
         } elseif (!empty($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
             $productInfo['primaryPrice'] = $productObj->getPrice();
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             unset($productInfo['volume_based_pricing']);
         }
         if (isset($productInfo['code_info'])) {
             if ($productInfo['code_info']['type'] != 'fixed' && isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 $discountTotalAmount += (double) $productInfo['count_listings'][$productInfo['number_of_listings']]['percentPromoAmount'];
             } else {
                 $discountTotalAmount += (double) $productInfo['code_info']['promoAmount'];
             }
         }
         if (empty($productInfo['volume_based_pricing'])) {
             $productInfo['primaryPrice'] = $productExtraInfo['price'];
             $this->applyPromoCodesToProduct($promotionCode, $productInfo);
             $totalPrice += (double) $productInfo['price'];
         }
         $products[$key] = $productInfo;
         $products[$key]['item_sid'] = $product['sid'];
     }
     if ($currentUser) {
         $taxInfo = SJB_TaxesManager::getTaxInfoByUserSidAndPrice($currentUser->getSID(), $totalPrice);
         $tp->assign('tax', $taxInfo);
     }
     $userGroupID = $productInfo ? SJB_UserGroupDBManager::getUserGroupIDBySID($productInfo['user_group_sid']) : false;
     $tp->assign('promotionCodeAlreadyUsed', $promotionCode && empty($errors));
     if (isset($promotionCodeInfo)) {
         $tp->assign('promotionCodeInfo', $promotionCodeInfo);
     }
     $tp->assign('error', $error);
     $tp->assign('errors', $errors);
     $tp->assign('total_price', $totalPrice);
     $tp->assign('discountTotalAmount', $discountTotalAmount);
     $tp->assign('products', $products);
     $tp->assign('userGroupID', $userGroupID);
     $tp->assign('account_activated', SJB_Request::getVar('account_activated', ''));
     $tp->display('shopping_cart.tpl');
 }
Esempio n. 3
0
 public static function getUserGroupSIDByName($user_group_name)
 {
     return SJB_UserGroupDBManager::getUserGroupSIDByName($user_group_name);
 }