コード例 #1
0
ファイル: add_product.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $productType = SJB_Request::getVar('product_type', false);
     $action = SJB_Request::getVar('action', false);
     $errors = array();
     $productErrors = array();
     if ($productType) {
         if ($productType == 'featured_user') {
             $_REQUEST['user_group_sid'] = SJB_UserGroupManager::getUserGroupSIDByID('Employer');
         }
         $product = new SJB_Product($_REQUEST, $productType);
         $pages = $product->getProductPages();
         $addProductForm = new SJB_Form($product);
         $addProductForm->registerTags($tp);
         $form_submitted = SJB_Request::getVar('action', '') == 'save';
         if ($form_submitted) {
             $productErrors = $product->isValid($product);
             if (in_array($productType, array('access_listings', 'featured_user', 'banners', 'custom_product'))) {
                 $periodName = $product->getPropertyValue('period_name');
                 if ($periodName == 'unlimited') {
                     $product->makePropertyNotRequired('period');
                 }
             }
         }
         if ($form_submitted && $addProductForm->isDataValid($errors) && !$productErrors) {
             $product->addProperty(array('id' => 'product_type', 'type' => 'string', 'value' => $productType, 'is_system' => true));
             $product->saveProduct($product, $_REQUEST);
             $product->savePermissions($_REQUEST);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/products/');
         }
         $errors = array_merge($errors, $productErrors);
         $formFieldsInfo = $addProductForm->getFormFieldsInfo();
         $formFields = array();
         foreach ($pages as $pageID => $page) {
             foreach ($formFieldsInfo as $formFieldInfo) {
                 if (in_array($formFieldInfo['id'], $page['fields'])) {
                     $formFields[$pageID][] = $formFieldInfo;
                 }
             }
             if (!isset($formFields[$pageID])) {
                 $formFields[$pageID] = array();
             }
         }
         $tp->assign('form_fields', $formFields);
         $tp->assign('product_type', $productType);
         $tp->assign('request', $_REQUEST);
         $tp->assign('params', http_build_query($_REQUEST));
         $tp->assign('pages', $pages);
         $tp->assign('pageTab', SJB_Request::getVar('page', false));
         $tp->assign("errors", $errors);
         $tp->display('add_product.tpl');
     } else {
         $tp->display('select_product_type.tpl');
     }
 }
コード例 #2
0
ファイル: pay_for_listing.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $templateProcessor = SJB_System::getTemplateProcessor();
     $listingSid = isset($_REQUEST['listing_id']) ? $_REQUEST['listing_id'] : null;
     $listing = SJB_ListingManager::getObjectBySID($listingSid);
     if (!is_null($listing) && !$listing->isActive()) {
         $listingInfo = SJB_ListingManager::getListingInfoBySID($listingSid);
         $productInfo = !empty($listingInfo['product_info']) ? unserialize($listingInfo['product_info']) : array();
         if (isset($listingInfo['complete']) && $listingInfo['complete'] == 1 && $listingInfo['checkouted'] == 1) {
             $subTotalPrice = 0;
             // проверить истек ли листинг, если истек , прайс прировнять к renewal_price
             if (SJB_ListingManager::getIfListingHasExpiredBySID($listing->getID()) && isset($productInfo['renewal_price'])) {
                 $subTotalPrice = $productInfo['renewal_price'];
             }
             $userSid = $listing->getUserSID();
             $productSid = $productInfo['product_sid'];
             $listingTitle = $listing->getProperty('Title')->getValue();
             $listingTypeSid = $listing->getListingTypeSID();
             $listingTypeId = SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid);
             $newProductName = "Reactivation of \"{$listingTitle}\" {$listingTypeId}";
             $newProductInfo = SJB_ShoppingCart::createInfoForCustomProduct($userSid, $productSid, $listingSid, $subTotalPrice, $newProductName, 'activateListing');
             if ($subTotalPrice <= 0) {
                 if (SJB_ListingManager::activateListingBySID($listing->getSID())) {
                     SJB_Notifications::sendUserListingActivatedLetter($listing, $listing->getUserSID());
                 }
             } else {
                 SJB_ShoppingCart::createCustomProduct($newProductInfo, $userSid);
                 $shoppingUrl = SJB_System::getSystemSettings('SITE_URL') . '/shopping-cart/';
                 SJB_HelperFunctions::redirect($shoppingUrl);
             }
             $templateProcessor->assign('listingTypeID', SJB_ListingTypeManager::getListingTypeIDBySID($listingTypeSid));
         } elseif ($listingInfo['checkouted'] == 0) {
             $productsInfoFromShopppingCart = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($productInfo['product_sid'], $listing->getUserSID());
             if (empty($productsInfoFromShopppingCart)) {
                 $productInfoToShopCart = SJB_ProductsManager::getProductInfoBySID($productInfo['product_sid']);
                 $productInfo['number_of_listings'] = 1;
                 $productObj = new SJB_Product($productInfoToShopCart, $productInfoToShopCart['product_type']);
                 $productObj->setNumberOfListings($productInfoToShopCart['number_of_listings']);
                 $productInfoToShopCart['price'] = $productObj->getPrice();
                 SJB_ShoppingCart::addToShoppingCart($productInfoToShopCart, $listing->getUserSID());
             }
             SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
         } else {
             $errors['LISTING_IS_NOT_COMPLETE'] = 1;
         }
     } elseif (is_null($listingSid)) {
         $errors['INVALID_LISTING_ID'] = 1;
     } elseif (!is_null($listing) && $listing->isActive()) {
         $errors['LISTING_ALREADY_ACTIVE'] = 1;
     } else {
         $errors['WRONG_LISTING_ID_SPECIFIED'] = 1;
     }
     $templateProcessor->assign("errors", isset($errors) ? $errors : null);
     $templateProcessor->display("pay_for_listing.tpl");
 }
コード例 #3
0
ファイル: products.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $sid = SJB_Request::getVar('sid', 0);
     $errors = array();
     switch ($action) {
         case 'activate':
             SJB_ProductsManager::activateProductBySID($sid);
             break;
         case 'deactivate':
             SJB_ProductsManager::deactivateProductBySID($sid);
             break;
         case 'delete':
             if (SJB_ContractManager::getContractQuantityByProductSID($sid) || SJB_InvoiceManager::getInvoiceQuantityByProductSID($sid)) {
                 $errors['PRODUCT_IS_IN_USE'] = 1;
             } else {
                 SJB_ProductsManager::deleteProductBySID($sid);
             }
             break;
     }
     $products = SJB_ProductsManager::getAllProductsInfo();
     foreach ($products as $key => $productInfo) {
         $product = new SJB_Product($productInfo, $productInfo['product_type']);
         $product->setNumberOfListings(1);
         if ($productInfo['product_type'] != 'post_listings' && $productInfo['product_type'] != 'mixed_product') {
             $products[$key]['number_of_postings'] = '-';
         }
         $products[$key]['price'] = $product->getPrice();
         $products[$key]['user_group'] = SJB_UserGroupManager::getUserGroupInfoBySID($productInfo['user_group_sid']);
         $products[$key]['product_type'] = SJB_ProductsManager::getProductTypeByID($productInfo['product_type']);
         $products[$key]['subscribed_users'] = SJB_ContractManager::getContractQuantityByProductSID($productInfo['sid']);
         $products[$key]['invoices'] = SJB_InvoiceManager::getInvoiceQuantityByProductSID($productInfo['sid']);
         if (!empty($productInfo['availability_to']) && $productInfo['availability_to'] <= date('Y-m-d')) {
             $products[$key]['expired'] = 1;
         }
     }
     $tp->assign('errors', $errors);
     $tp->assign('products', $products);
     $tp->display('products.tpl');
 }
コード例 #4
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $currentUser = SJB_UserManager::getCurrentUser();
     $products = array();
     if (!empty($_SESSION['products'])) {
         $products = $_SESSION['products'];
     }
     if (SJB_UserManager::isUserLoggedIn()) {
         foreach ($products as $product) {
             if (!empty($product['product_info'])) {
                 $productInfo = unserialize($product['product_info']);
                 if ($currentUser->getUserGroupSID() != $productInfo['user_group_sid']) {
                     SJB_Session::unsetValue('products');
                     SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . "/shopping-cart/?error=user_group");
                 } else {
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUser->getSID());
                 }
             }
         }
         SJB_Session::unsetValue('products');
         $products = SJB_ShoppingCart::getAllProductsByUserSID($currentUser->getSID());
     }
     $total_price = 0;
     foreach ($products as $product) {
         $productInfo = unserialize($product['product_info']);
         $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();
         $total_price += $productInfo['price'];
         if ($productInfo['pricing_type'] != 'volume_based' && $productInfo['code_info']) {
             $total_price += $productInfo['code_info']['promoAmount'];
         }
     }
     $tp->assign('products_number', count($products));
     $tp->assign('total_price', $total_price);
     $tp->assign("currency", SJB_CurrencyManager::getDefaultCurrency());
     $tp->display('show_shopping_cart.tpl');
 }
コード例 #5
0
ファイル: shopping_cart.php プロジェクト: Maxlander/shixi
 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');
 }
コード例 #6
0
ファイル: PayPal.php プロジェクト: Maxlander/shixi
 /**
  * @param  $invoice SJB_Invoice
  * @return array
  */
 function getFormFields($invoice)
 {
     $form_fields = array();
     $properties = $this->details->getProperties();
     $id = $properties['id']->getValue();
     if ($invoice->isRecurring()) {
         // hard-coded fields
         $form_fields['cmd'] = '_xclick-subscriptions';
         $form_fields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/notifications/{$id}/";
         $form_fields['return'] = SJB_System::getSystemSettings('SITE_URL') . '/my-products/?subscriptionComplete=true';
         $form_fields['src'] = '1';
         $recurringProduct = array();
         $products = array();
         $items = $invoice->getPropertyValue('items');
         if (!empty($items['products'])) {
             foreach ($items['products'] as $key => $product) {
                 if ($product != -1) {
                     $productInfo = $invoice->getItemValue($key);
                     if (!empty($productInfo['recurring']) && !$recurringProduct) {
                         $recurringProduct = $productInfo;
                     }
                     $products[] = $productInfo;
                 }
             }
         }
         $taxInfo = $invoice->getPropertyValue('tax_info');
         if ($taxInfo && !$taxInfo['price_includes_tax']) {
             $recurringProduct['price'] += SJB_TaxesManager::getTaxAmount($recurringProduct['price'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
         }
         $product = new SJB_Product($recurringProduct, $recurringProduct['product_type']);
         if (count($products) > 1) {
             $form_fields['a1'] = $invoice->getPropertyValue('total');
             $form_fields['p1'] = $product->getExpirationPeriod();
             $form_fields['t1'] = 'D';
         }
         $form_fields['a3'] = $recurringProduct['price'];
         $form_fields['p3'] = $product->getExpirationPeriod();
         $form_fields['t3'] = 'D';
         $form_fields['custom'] = $recurringProduct['sid'];
         $form_fields['no_note'] = '1';
         $form_fields['no_shipping'] = '1';
     } else {
         // hard-coded fields
         $form_fields['cmd'] = '_xclick';
         $form_fields['amount'] = $invoice->getPropertyValue('total');
         $form_fields['return'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
         $form_fields['notify_url'] = SJB_System::getSystemSettings('SITE_URL') . "/system/payment/callback/{$id}/{$invoice->getSID()}/";
     }
     $form_fields['cancel_return'] = SJB_System::getSystemSettings('SITE_URL') . "/my-account/";
     $form_fields['rm'] = 2;
     // POST method for call back
     // configuration fields
     $form_fields['business'] = $properties['paypal_account_email']->getValue();
     $form_fields['currency_code'] = $properties['currency_code']->getValue();
     // payment-related fields
     $form_fields['item_name'] = $invoice->getProductNames();
     $form_fields['item_number'] = $invoice->getSID();
     return $form_fields;
 }
コード例 #7
0
ファイル: edit_product.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $updateUsers = SJB_Request::getVar('update_users', 0);
     $sid = SJB_Request::getVar('sid', 0);
     $errors = array();
     $productErrors = array();
     $productInfo = SJB_ProductsManager::getProductInfoBySID($sid);
     if ($productInfo) {
         if ($productInfo['product_type'] == 'featured_user') {
             $_REQUEST['user_group_sid'] = SJB_UserGroupManager::getUserGroupSIDByID('Employer');
         }
         $productInfo = array_merge($productInfo, $_REQUEST);
         $product = new SJB_Product($productInfo, $productInfo['product_type']);
         $product->setSID($sid);
         $pages = $product->getProductPages();
         $editProductForm = new SJB_Form($product);
         $editProductForm->registerTags($tp);
         $form_submitted = $action == 'save' || $action == 'apply_product';
         $activeError = array();
         if ($form_submitted && ($productInfo['active'] = 1)) {
             if (!empty($productInfo['availability_to']) && SJB_I18N::getInstance()->getInput('date', $productInfo['availability_to']) <= date('Y-m-d')) {
                 $activeError['INVALID_ACTIVATION'] = 'The product cannot be activated. Please change the availability date.';
             }
         }
         if ($form_submitted) {
             $productErrors = $product->isValid($product);
             $activeError = array_merge($activeError, $productErrors);
             if (in_array($productInfo['product_type'], array('access_listings', 'featured_user', 'banners', 'custom_product'))) {
                 $periodName = $product->getPropertyValue('period_name');
                 if ($periodName == 'unlimited') {
                     $product->makePropertyNotRequired('period');
                 }
             }
         }
         if ($form_submitted && $editProductForm->isDataValid($errors) && !$activeError) {
             $product->saveProduct($product);
             $product->savePermissions($_REQUEST);
             if ($updateUsers) {
                 $contracts = SJB_ContractManager::getAllContractsByProductSID($product->getSID());
                 if ($contracts) {
                     $contractsSIDs = array();
                     foreach ($contracts as $contract) {
                         $contractsSIDs[] = $contract['id'];
                     }
                     $contractsSIDs = implode(',', $contractsSIDs);
                     SJB_ContractSQL::updateAllContractsExtraInfoByProductSID($contractsSIDs, $product->getSID());
                 }
             }
             if ($action == 'save') {
                 SJB_HelperFunctions::redirect(SJB_System::getSystemSettings('SITE_URL') . '/products/');
             }
         } else {
             $product->setFloatNumbersIntoValidFormat();
         }
         $errors = array_merge($errors, $activeError);
         $formFieldsInfo = $editProductForm->getFormFieldsInfo();
         $formFields = array();
         foreach ($pages as $pageID => $page) {
             foreach ($formFieldsInfo as $formFieldInfo) {
                 if (in_array($formFieldInfo['id'], $page['fields'])) {
                     $formFields[$pageID][] = $formFieldInfo;
                 }
             }
             if (!isset($formFields[$pageID])) {
                 $formFields[$pageID] = array();
             }
         }
         $tp->assign('form_fields', $formFields);
         $tp->assign('product_info', $productInfo);
         $tp->assign('product_type', $productInfo['product_type']);
         $tp->assign('params', http_build_query($_REQUEST));
         $tp->assign('pageTab', SJB_Request::getVar('page', false));
         $tp->assign('pages', $pages);
         $tp->assign("errors", $errors);
         $tp->display('edit_product.tpl');
     }
 }
コード例 #8
0
ファイル: products.php プロジェクト: Maxlander/shixi
 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);
 }
コード例 #9
0
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $userGroupSid = SJB_Request::getVar('user_group_sid', false);
     $productType = SJB_Request::getVar('product_type', false);
     $permissions_type = SJB_Request::getVar('permissions_type', 'additional');
     $addedPermissions = false;
     $role = SJB_Request::getVar('role', false);
     $type = 'product';
     $acl = SJB_Acl::getInstance(true);
     $resources = $acl->getResources($type);
     $product = new SJB_Product(array(), $productType);
     $additionalPermissions = $product->getAdditionalPermissions();
     $accessPermissions = $product->getAccessPermissions();
     $perms = SJB_DB::query('select * from `permissions` where `type` = ?s and `role` = ?s', $type, $role);
     $countGeneralPermissions = 0;
     foreach ($resources as $key => $resource) {
         switch ($permissions_type) {
             case 'additional':
                 if (!in_array($key, $additionalPermissions)) {
                     unset($resources[$key]);
                     continue;
                 }
                 break;
             case 'access':
                 if (!in_array($key, $accessPermissions)) {
                     unset($resources[$key]);
                     continue;
                 }
                 break;
         }
         $resources[$key]['value'] = 'inherit';
         $resources[$key]['name'] = $key;
         foreach ($perms as $perm) {
             if ($key == $perm['name']) {
                 $resources[$key]['value'] = $perm['value'];
                 $resources[$key]['params'] = $perm['params'];
                 $resources[$key]['message'] = $perm['message'];
                 break;
             }
         }
         if (!empty($addedPermissions[$key])) {
             $params = isset($addedPermissions[$key . '_params']) ? $addedPermissions[$key . '_params'] : '';
             $params1 = isset($addedPermissions[$key . '_params1']) ? $addedPermissions[$key . '_params1'] : '';
             $message = isset($addedPermissions[$key . '_message']) ? $addedPermissions[$key . '_message'] : '';
             if ($addedPermissions[$key] == 'deny' && $params1) {
                 $params = $params1;
             }
             $resources[$key]['value'] = $addedPermissions[$key];
             $resources[$key]['params'] = $params;
             $resources[$key]['message'] = $message;
         }
         if (isset($resources[$key]['group']) && $resources[$key]['group'] == 'general') {
             $countGeneralPermissions++;
         }
     }
     $tp->assign('countGeneralPermissions', $countGeneralPermissions);
     $tp->assign('resources', $resources);
     $tp->assign('listingTypes', SJB_ListingTypeManager::getAllListingTypesInfo());
     $tp->assign('role', $role);
     $tp->assign('type', $type);
     $tp->assign('user_group_sid', $userGroupSid);
     $tp->display('product_permissions.tpl');
 }
コード例 #10
0
ファイル: AuthNetARB.php プロジェクト: Maxlander/shixi
 function createSubscription($payment_data)
 {
     $validation_result = $this->validatePayment($payment_data);
     if ($validation_result !== true) {
         return $validation_result;
     }
     $properties = $this->details->getProperties();
     $api_login_id = $properties['authnet_api_login_id']->getValue();
     $transaction_key = $properties['authnet_api_transaction_key']->getValue();
     $use_test_account = $properties['authnet_use_test_account']->getValue();
     $invoice = SJB_InvoiceManager::getObjectBySID($payment_data['item_number']);
     if (empty($invoice)) {
         return;
     }
     $items = $invoice->getPropertyValue('items');
     $taxInfo = $invoice->getPropertyValue('tax_info');
     if (!empty($items['products'])) {
         foreach ($items['products'] as $key => $product) {
             if ($product != -1) {
                 $product_info = $invoice->getItemValue($key);
                 $payment_data['item_number'] = $invoice->getSID();
                 $payment_data['item_name'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_description'] = 'Payment for product ' . $product_info['name'];
                 $payment_data['x_amount'] = $product_info['amount'];
                 if ($taxInfo && !$taxInfo['price_includes_tax']) {
                     $payment_data['x_amount'] += SJB_TaxesManager::getTaxAmount($payment_data['x_amount'], $taxInfo['tax_rate'], $taxInfo['price_includes_tax']);
                 }
                 $aimProcessor = new AuthnetAIMProcessor($api_login_id, $transaction_key, $use_test_account);
                 $aimProcessor->setTransactionType('AUTH_CAPTURE');
                 $aimProcessor->setParameter('x_login', $api_login_id);
                 $aimProcessor->setParameter('x_tran_key', $transaction_key);
                 $aimProcessor->setParameter('x_card_num', $payment_data['x_card_num']);
                 $aimProcessor->setParameter('x_amount', $payment_data['x_amount']);
                 $aimProcessor->setParameter('x_exp_date', $payment_data['x_exp_date']);
                 $aimProcessor->process();
                 if (!$aimProcessor->isApproved()) {
                     return array($aimProcessor->getResponseMessage());
                 }
                 $recurringID = null;
                 if (!empty($product_info['recurring'])) {
                     $product = new SJB_Product($product_info, $product_info['product_type']);
                     $expiration_period = $product->getExpirationPeriod();
                     $arbProcessor = new AuthnetARBProcessor($api_login_id, $transaction_key, $use_test_account);
                     $arbProcessor->setParameter('refID', $payment_data['item_number']);
                     $arbProcessor->setParameter('subscrName', $payment_data['x_description']);
                     $arbProcessor->setParameter('interval_length', $expiration_period);
                     $arbProcessor->setParameter('interval_unit', 'days');
                     $arbProcessor->setParameter('startDate', date("Y-m-d", strtotime("+ {$expiration_period} days")));
                     $arbProcessor->setParameter('totalOccurrences', 9999);
                     $arbProcessor->setParameter('trialOccurrences', 0);
                     $arbProcessor->setParameter('amount', $payment_data['x_amount']);
                     $arbProcessor->setParameter('trialAmount', 0.0);
                     $arbProcessor->setParameter('cardNumber', $payment_data['x_card_num']);
                     $arbProcessor->setParameter('expirationDate', $payment_data['x_exp_date']);
                     $arbProcessor->setParameter('orderInvoiceNumber', $payment_data['item_number']);
                     $arbProcessor->setParameter('orderDescription', $payment_data['x_description']);
                     $arbProcessor->setParameter('firstName', $payment_data['x_first_name']);
                     $arbProcessor->setParameter('lastName', $payment_data['x_last_name']);
                     $arbProcessor->setParameter('company', $payment_data['x_company']);
                     $arbProcessor->setParameter('address', $payment_data['x_address']);
                     $arbProcessor->setParameter('city', $payment_data['x_city']);
                     $arbProcessor->setParameter('state', $payment_data['x_state']);
                     $arbProcessor->setParameter('zip', $payment_data['x_zip']);
                     $arbProcessor->createAccount();
                     if (!$arbProcessor->isSuccessful()) {
                         return array($arbProcessor->getResponse());
                     }
                     $recurringID = $arbProcessor->getSubscriberID();
                 }
                 $user_sid = $invoice->getUserSID();
                 $listingNumber = $product_info['qty'];
                 $contract = new SJB_Contract(array('product_sid' => $product, 'recurring_id' => $recurringID, 'gateway_id' => 'authnet_sim', 'numberOfListings' => $listingNumber));
                 $contract->setUserSID($user_sid);
                 $contract->setPrice($product_info['amount']);
                 if ($contract->saveInDB()) {
                     SJB_ShoppingCart::deleteItemFromCartBySID($product_info['shoppingCartRecord'], $user_sid);
                     $bannerInfo = $product_info['banner_info'];
                     if ($product_info['product_type'] == 'banners' && !empty($bannerInfo)) {
                         $bannersObj = new SJB_Banners();
                         $bannersObj->addBanner($bannerInfo['title'], $bannerInfo['link'], $bannerInfo['bannerFilePath'], $bannerInfo['sx'], $bannerInfo['sy'], $bannerInfo['type'], 0, $bannerInfo['banner_group_sid'], $bannerInfo, $user_sid, $contract->getID());
                         $bannerGroup = $bannersObj->getBannerGroupBySID($bannerInfo['banner_group_sid']);
                         SJB_AdminNotifications::sendAdminBannerAddedLetter($user_sid, $bannerGroup);
                     }
                     if ($contract->isFeaturedProfile()) {
                         SJB_UserManager::makeFeaturedBySID($user_sid);
                     }
                     if (SJB_UserNotificationsManager::isUserNotifiedOnSubscriptionActivation($user_sid)) {
                         SJB_Notifications::sendSubscriptionActivationLetter($user_sid, $product_info);
                     }
                 }
             }
         }
         $invoice->setCallbackData($payment_data);
         $invoice->setStatus(SJB_Invoice::INVOICE_STATUS_PAID);
         SJB_InvoiceManager::saveInvoice($invoice);
         SJB_PromotionsManager::markPromotionAsPaidByInvoiceSID($invoice->getSID());
     }
     return true;
 }
コード例 #11
0
ファイル: add_listing.php プロジェクト: Maxlander/shixi
 /**
  * @param int $currentUserID
  * @param int $productSID
  * @return bool|int|mixed
  */
 public function proceedToCheckout($currentUserID, $productSID)
 {
     $errors = array();
     $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
     if (SJB_UserManager::isUserLoggedIn()) {
         $numberOfListings = SJB_ListingDBManager::getNumberOfCheckoutedListingsByProductSID($productSID, $currentUserID);
         $extraInfo = SJB_ProductsManager::getProductExtraInfoBySID($productSID);
         $shoppingCartProducts = SJB_ShoppingCart::getProductsInfoFromCartByProductSID($productSID, $currentUserID);
         if (!empty($shoppingCartProducts)) {
             if ($productInfo['product_type'] == 'mixed_product' || isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'fixed') {
                 if ($numberOfListings / (count($shoppingCartProducts) * $productInfo['number_of_listings']) > 1) {
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
                 }
             }
             if (isset($productInfo['pricing_type']) && $productInfo['pricing_type'] == 'volume_based') {
                 if ($numberOfListings / (count($shoppingCartProducts) * end($productInfo['volume_based_pricing']['listings_range_to'])) > 1) {
                     $productInfo['number_of_listings'] = 1;
                     $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                     $productObj->setNumberOfListings($productInfo['number_of_listings']);
                     $productInfo['price'] = $productObj->getPrice();
                     SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
                 } else {
                     foreach ($shoppingCartProducts as $shoppingCartProduct) {
                         $unserializedProductInfoFromShopCart = unserialize($shoppingCartProduct['product_info']);
                         if ($unserializedProductInfoFromShopCart['number_of_listings'] < end($unserializedProductInfoFromShopCart['volume_based_pricing']['listings_range_to'])) {
                             $unserializedProductInfoFromShopCart['number_of_listings'] += 1;
                             SJB_ShoppingCart::updateItemBySID($shoppingCartProduct['sid'], $unserializedProductInfoFromShopCart);
                             break;
                         }
                     }
                 }
             }
         } else {
             if (!empty($extraInfo['pricing_type']) && $extraInfo['pricing_type'] == 'volume_based') {
                 $productInfo['number_of_listings'] = 1;
                 $productObj = new SJB_Product($productInfo, $productInfo['product_type']);
                 $productObj->setNumberOfListings($productInfo['number_of_listings']);
                 $productInfo['price'] = $productObj->getPrice();
             }
             SJB_ShoppingCart::addToShoppingCart($productInfo, $currentUserID);
         }
     } else {
         $products = SJB_Session::getValue('products');
         if (isset($products)) {
             foreach ($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();
             $products[$id]['product_info'] = serialize($productInfo);
             $products[$id]['sid'] = $id;
             $products[$id]['user_sid'] = 0;
             SJB_Session::setValue('products', $products);
         }
     }
     if (!$errors) {
         SJB_HelperFunctions::redirect(SJB_System::getSystemsettings('SITE_URL') . '/shopping-cart/');
     }
 }
コード例 #12
0
ファイル: clone_product.php プロジェクト: Maxlander/shixi
 public function execute()
 {
     $tp = SJB_System::getTemplateProcessor();
     $action = SJB_Request::getVar('action', false);
     $sid = SJB_Request::getVar('sid', 0);
     $errors = array();
     $productErrors = array();
     $productInfo = SJB_ProductsManager::getProductInfoBySID($sid);
     if ($productInfo) {
         if ($productInfo['product_type'] == 'featured_user') {
             $_REQUEST['user_group_sid'] = SJB_UserGroupManager::getUserGroupSIDByID('Employer');
         }
         $productInfo = array_merge($productInfo, $_REQUEST);
         $product = new SJB_Product($productInfo, $productInfo['product_type']);
         $pages = $product->getProductPages();
         $editProductForm = new SJB_Form($product);
         $editProductForm->registerTags($tp);
         $form_submitted = SJB_Request::getVar('action', '') == 'save';
         if ($form_submitted && in_array($productInfo['product_type'], array('access_listings', 'featured_user', 'banners', 'custom_product'))) {
             $periodName = $product->getPropertyValue('period_name');
             if ($periodName == 'unlimited') {
                 $product->makePropertyNotRequired('period');
             }
         }
         $activeError = array();
         if ($form_submitted && ($productInfo['active'] = 1)) {
             if (!empty($productInfo['availability_to']) && SJB_I18N::getInstance()->getInput('date', $productInfo['availability_to']) <= date('Y-m-d')) {
                 $activeError['INVALID_ACTIVATION'] = 'The product cannot be activated. Please change the availability date.';
             }
         }
         if ($form_submitted) {
             $productErrors = $product->isValid($product);
             $activeError = array_merge($activeError, $productErrors);
         }
         if ($form_submitted && $editProductForm->isDataValid($errors) && !$activeError) {
             $product->addProperty(array('id' => 'product_type', 'type' => 'string', 'value' => $productInfo['product_type'], 'is_system' => true));
             $product->saveProduct($product, $_REQUEST);
             $product->savePermissions($_REQUEST);
             SJB_HelperFunctions::redirect(SJB_System::getSystemSettings("SITE_URL") . '/edit-product/?sid=' . $product->getSID());
         }
         $errors = array_merge($errors, $activeError);
         $formFieldsInfo = $editProductForm->getFormFieldsInfo();
         $formFields = array();
         foreach ($pages as $pageID => $page) {
             foreach ($formFieldsInfo as $formFieldInfo) {
                 if (in_array($formFieldInfo['id'], $page['fields'])) {
                     $formFields[$pageID][] = $formFieldInfo;
                 }
             }
             if (!isset($formFields[$pageID])) {
                 $formFields[$pageID] = array();
             }
         }
         $tp->assign('form_fields', $formFields);
         $tp->assign('product_info', $productInfo);
         $tp->assign('product_type', $productInfo['product_type']);
         $tp->assign('pages', $pages);
         $tp->assign('pageTab', SJB_Request::getVar('page', false));
         $tp->assign("errors", $errors);
         $tp->display('clone_product.tpl');
     }
 }
コード例 #13
0
ファイル: ContractManager.php プロジェクト: Maxlander/shixi
 public static function updateExpirationPeriod($contractSID)
 {
     $contractInfo = self::getInfo($contractSID);
     if ($contractInfo) {
         $productInfo = SJB_ProductsManager::getProductInfoBySID($contractInfo['product_sid']);
         $product = new SJB_Product($productInfo, $productInfo['product_type']);
         $is_recurring = !empty($productInfo['is_recurring']) ? $productInfo['is_recurring'] : false;
         $expirationPeriod = $product->getExpirationPeriod();
         if ($expirationPeriod) {
             if ($is_recurring) {
                 // Для рекьюринг планов, делаем запас для проплаты в 1 день
                 $expirationPeriod++;
             }
             $expired_date = date("Y-m-d", strtotime("+" . $expirationPeriod . " day"));
             SJB_DB::query("UPDATE `contracts` SET `expired_date` = ?s WHERE `id` = ?n", $expired_date, $contractSID);
         }
     }
 }
コード例 #14
0
ファイル: PayPalPro.php プロジェクト: Maxlander/shixi
 private function getCustomerInfoQueryForRecurring($data, $recurring = false)
 {
     $query = array();
     $expDateMonth = $data['exp_date_mm'];
     $padDateMonth = urlencode(str_pad($expDateMonth, 2, '0', STR_PAD_LEFT));
     if ($recurring == false) {
         if (!empty($data['products'])) {
             $dataArray = $data['products'];
         } else {
             return '';
         }
     } elseif (!empty($data['recurring'])) {
         $dataArray = $data['recurring'];
     } else {
         return '';
     }
     foreach ($dataArray as $key => $products) {
         $product = new SJB_Product($products, $products['product_type']);
         $expPeriod = $product->getExpirationPeriod();
         $customer = array('TOKEN' => '', 'CREDITCARDTYPE' => '', 'ACCT' => urlencode($data['card_number']), 'EXPDATE' => $padDateMonth . ($expDateYear = urlencode($data['exp_date_yy'])), 'FIRSTNAME' => urlencode($data['first_name']), 'LASTNAME' => urlencode($data['last_name']), 'PROFILESTARTDATE' => date('Y-n-d') . 'T' . date('G:i:s'), 'DESC' => urlencode($products['name']), 'BILLINGPERIOD' => urlencode('Day'), 'BILLINGFREQUENCY' => urlencode($expPeriod), 'CURRENCYCODE' => urlencode($data['currency_code']), 'AMT' => urlencode($products['price']), 'NOTIFYURL' => urlencode($data['notify_url']), 'ITEMNUMBER' => urlencode($data['item_number']), 'CUSTOM' => urlencode($products['sid']));
         if ($recurring === false) {
             $customer['TOTALBILLINGCYCLES'] = urlencode(1);
             if (empty($expPeriod)) {
                 $customer['BILLINGFREQUENCY'] = urlencode(30);
             }
         }
         $query[$key] = '&' . http_build_query($customer);
     }
     return $query;
 }
コード例 #15
0
ファイル: Contract.php プロジェクト: Maxlander/shixi
 function _constructorByProduct($productInfo)
 {
     $productSID = $productInfo['product_sid'];
     $numberOfListings = isset($productInfo['numberOfListings']) ? $productInfo['numberOfListings'] : false;
     $this->product_sid = $productSID;
     $productInfo = SJB_ProductsManager::getProductInfoBySID($productSID);
     $is_recurring = !empty($productInfo['recurring']) ? $productInfo['recurring'] : false;
     if ($productInfo['product_type'] == 'featured_user') {
         $this->featured_profile = true;
     }
     $this->product_type = $productInfo['product_type'];
     $product = new SJB_Product($productInfo, $productInfo['product_type']);
     if ($numberOfListings) {
         $product->setNumberOfListings($numberOfListings);
     } else {
         $numberOfListings = !empty($productInfo['number_of_listings']) ? $productInfo['number_of_listings'] : 0;
     }
     $this->setNumberOfListings($numberOfListings);
     $expirationPeriod = $product->getExpirationPeriod();
     if ($expirationPeriod) {
         if ($is_recurring) {
             // Для рекьюринг планов, делаем запас для проплаты в 1 день
             $expirationPeriod++;
         }
         $this->expired_date = date("Y-m-d", strtotime("+" . $expirationPeriod . " day"));
     }
     $this->price = $product->getPrice();
 }