コード例 #1
0
ファイル: Catalog.php プロジェクト: j0nbr0wn/zilla_heroku
 /**
  * Reads the Product Catalog Data from Zuora and saves it to a JSON cache stored on the server to reduce load times. This method must be called each time the Product Catalog is changed in Zuora to ensure the catalog is not out of date for the user.
  * @return A model containing all necessary information needed to display the products and rate plans in the product catalog
  */
 public static function refreshCache()
 {
     //Initialize Zuora API Instance
     include './config.php';
     $zapi = new zApi();
     // if guided selling filter fields exist, loop through and create string for the query
     $guidedSellingFieldsString = '';
     if (count($guidedSellingFields) > 0) {
         $guidedSellingFieldsString = ',' . implode(",", $guidedSellingFields);
     }
     //For each classification
     $fieldGroups;
     $numGroups;
     if ($showAllProducts) {
         $numGroups = 1;
         $fieldGroups = array('');
     } else {
         $numGroups = count($groupingFieldValues);
         $fieldGroups = $groupingFieldValues;
     }
     $catalog_groups = array();
     foreach ($fieldGroups as $fieldGroup) {
         $catalog_group = new Catalog_Group();
         if ($fieldGroup == 'Base Product') {
             $catalog_group->isBase = true;
         } elseif ($fieldGroup == 'Add-On Product') {
             $catalog_group->isAddon = true;
             // } elseif ($fieldGroup == 'Partner') {
             // 	$catalog_group->isPartner = true;
         } else {
             $catalog_group->isHidden = true;
         }
         $catalog_group->Name = $fieldGroup;
         $catalog_group->products = array();
         date_default_timezone_set('America/Los_Angeles');
         $curDate = date('Y-m-d\\TH:i:s', time());
         //Get All Products
         $productZoql = "select Id,Name,SKU,Description" . $guidedSellingFieldsString . " from Product where EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "'";
         if (!$showAllProducts) {
             $productZoql .= " and " . $groupingField . "='" . $fieldGroup . "'";
         }
         $result = $zapi->zQuery($productZoql);
         $qProducts = array();
         if ($result->result != null) {
             $qProducts = $result->result->records;
         } else {
             addErrors(null, 'No Products found.');
             return;
         }
         //Set up Catalog_Product objects
         foreach ($qProducts as $p) {
             $catalog_product = new Catalog_Product();
             $catalog_product->Id = $p->Id;
             $catalog_product->Name = $p->Name;
             $catalog_product->Description = isset($p->Description) ? $p->Description : "";
             $catalog_product->SKU = $p->SKU;
             // loop through the guided selling fields from config file
             if (count($guidedSellingFields) > 0) {
                 $guidedFieldsArray = array();
                 foreach ($guidedSellingFields as $filterField) {
                     // set the product to have the value of the guided selling field
                     $catalog_product->{$filterField} = isset($p->{$filterField}) ? $p->{$filterField} : "";
                     $guidedSellingValues = array();
                     if ($catalog_product->{$filterField} != "") {
                         $guidedFieldsArray[$filterField] = $catalog_product->{$filterField};
                     }
                 }
                 $catalog_product->filterValues = array();
                 array_push($catalog_product->filterValues, $guidedFieldsArray);
             }
             //Get RatePlans for this Product
             $result = $zapi->zQuery("select Id,Name,Description," . $promoField . " from ProductRatePlan where ProductId='" . $catalog_product->Id . "' and EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "' ");
             $qRatePlans = array();
             $catalog_product->ratePlans = array();
             if ($result->result != null) {
                 $qRatePlans = $result->result->records;
                 if ($qRatePlans != null) {
                     foreach ($qRatePlans as $rp) {
                         $catalog_rateplan = new Catalog_RatePlan();
                         $catalog_rateplan->Id = $rp->Id;
                         $catalog_rateplan->Name = $rp->Name;
                         $catalog_rateplan->productName = $p->Name;
                         $catalog_rateplan->Description = isset($rp->Description) ? $rp->Description : "";
                         $catalog_rateplan->{$promoField} = isset($rp->{$promoField}) ? $rp->{$promoField} : "";
                         //Get Charges for the Rate Plan
                         $result = $zapi->zQuery("select Id,Name,DefaultQuantity,Description,UOM,ChargeModel,ChargeType,BillingPeriod from ProductRatePlanCharge where ProductRatePlanId='" . $catalog_rateplan->Id . "'");
                         $qCharges = array();
                         $catalog_rateplan->charges = array();
                         if ($result->result != null) {
                             $qCharges = $result->result->records;
                             if ($qCharges != null) {
                                 // start of for loop for rate plan charges
                                 foreach ($qCharges as $rpc) {
                                     $catalog_charge = new Catalog_Charge();
                                     $catalog_charge->Id = $rpc->Id;
                                     $catalog_charge->Name = $rpc->Name;
                                     $catalog_charge->Description = isset($rpc->Description) ? $rpc->Description : "";
                                     $catalog_charge->ChargeModel = $rpc->ChargeModel;
                                     $catalog_charge->ChargeType = $rpc->ChargeType;
                                     $catalog_charge->BillingPeriod = $rpc->BillingPeriod;
                                     if ($catalog_charge->ChargeModel == 'Tiered with Overage Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing') {
                                         $catalog_charge->Uom = $rpc->UOM;
                                         $catalog_charge->isTiered = true;
                                     }
                                     if ($catalog_charge->ChargeType != 'Usage' && ($catalog_charge->ChargeModel == 'Per Unit Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing')) {
                                         $catalog_charge->Uom = $rpc->UOM;
                                         $catalog_charge->quantifiable = true;
                                         $catalog_charge->DefaultQuantity = isset($rpc->DefaultQuantity) ? $rpc->DefaultQuantity : "1";
                                     }
                                     // probably need special case for ChargeModel == Overage Pricing to show overage price
                                     //MD New Lines to get detail for the individual charges
                                     $result = $zapi->zQuery("select Id,Price,Currency,Tier,StartingUnit,EndingUnit,PriceFormat from ProductRatePlanChargeTier where ProductRatePlanChargeId='" . $catalog_charge->Id . "'");
                                     $qChargeTiers = array();
                                     $catalog_charge->chargeTiers = array();
                                     if ($result->result != null) {
                                         usort($result->result->records, "Catalog::cmpTiers");
                                         $qChargeTiers = $result->result->records;
                                         if ($qChargeTiers != null) {
                                             foreach ($qChargeTiers as $rpct) {
                                                 $catalog_chargeTier = new Catalog_ChargeTier();
                                                 $catalog_chargeTier->Id = $rpct->Id;
                                                 $catalog_chargeTier->Price = $rpct->Price;
                                                 $catalog_chargeTier->Currency = $rpct->Currency;
                                                 $catalog_chargeTier->myCurrency = $rpct->Currency == $defaultCurrency;
                                                 $catalog_chargeTier->Tier = $rpct->Tier;
                                                 $catalog_chargeTier->StartingUnit = $rpct->StartingUnit;
                                                 $catalog_chargeTier->EndingUnit = $rpct->EndingUnit;
                                                 $catalog_chargeTier->PriceFormat = $rpct->PriceFormat;
                                                 array_push($catalog_charge->chargeTiers, $catalog_chargeTier);
                                             }
                                         }
                                     }
                                     //MD end new lines to get charge detail
                                     array_push($catalog_rateplan->charges, $catalog_charge);
                                 }
                             }
                         }
                         array_push($catalog_product->ratePlans, $catalog_rateplan);
                     }
                     array_push($catalog_group->products, $catalog_product);
                 }
             }
         }
         array_push($catalog_groups, $catalog_group);
     }
     $catalogJson = json_encode($catalog_groups);
     $lastSync = date(NULL);
     //Cache product list
     $myFile = $cachePath;
     $fh = fopen($myFile, 'w') or die("can't open file");
     fwrite($fh, $catalogJson);
     fclose($fh);
     return $catalog_groups;
 }
コード例 #2
0
ファイル: Amender.php プロジェクト: j0nbr0wn/zilla_heroku
 public static function getUpgradeDowngradePlans($updownSku)
 {
     //Initialize Zuora API Instance
     include './config.php';
     $zapi = new zApi();
     $_SESSION['myCurrency'] = $defaultCurrency;
     //For each classification
     date_default_timezone_set('America/Los_Angeles');
     $curDate = date('Y-m-d\\TH:i:s', time());
     //Get the Upgrade/Downgrade Product by SKU
     $productZoql = "select Id,Name,SKU,Description from Product where SKU='" . $updownSku . "' or Id='" . $updownSku . "' and EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "'";
     $result = $zapi->zQuery($productZoql);
     if ($result->result != null) {
         $qProduct = $result->result->records[0];
     } else {
         addErrors(null, 'No Products found.');
         return;
     }
     //Set up the Catalog_Product object
     $catalog_product = new Catalog_Product();
     $catalog_product->Id = $qProduct->Id;
     $catalog_product->Name = $qProduct->Name;
     $catalog_product->Description = isset($qProduct->Description) ? $qProduct->Description : "";
     $catalog_product->SKU = $qProduct->SKU;
     //Get RatePlans for this Product
     $result = $zapi->zQuery("select Id,Name,Description from ProductRatePlan where ProductId='" . $catalog_product->Id . "' and EffectiveStartDate<'" . $curDate . "' and EffectiveEndDate>'" . $curDate . "' ");
     $qRatePlans = array();
     $catalog_product->ratePlans = array();
     $qRatePlans = $result->result->records;
     if ($qRatePlans != null) {
         foreach ($qRatePlans as $rp) {
             $catalog_rateplan = new Catalog_RatePlan();
             $catalog_rateplan->Id = $rp->Id;
             $catalog_rateplan->Name = $rp->Name;
             $catalog_rateplan->productName = $qProduct->Name;
             $catalog_rateplan->Description = isset($rp->Description) ? $rp->Description : "";
             //Get Charges for the Rate Plan
             $result = $zapi->zQuery("select Id,Name,DefaultQuantity,Description,UOM,ChargeModel,ChargeType,BillingPeriod from ProductRatePlanCharge where ProductRatePlanId='" . $catalog_rateplan->Id . "'");
             $qCharges = array();
             $catalog_rateplan->charges = array();
             $qCharges = $result->result->records;
             if ($qCharges != null) {
                 // start of for loop for rate plan charges
                 foreach ($qCharges as $rpc) {
                     $catalog_charge = new Catalog_Charge();
                     $catalog_charge->Id = $rpc->Id;
                     $catalog_charge->Name = $rpc->Name;
                     $catalog_charge->Description = isset($rpc->Description) ? $rpc->Description : "";
                     $catalog_charge->ChargeModel = $rpc->ChargeModel;
                     $catalog_charge->ChargeType = $rpc->ChargeType;
                     $catalog_charge->BillingPeriod = $rpc->BillingPeriod;
                     if ($catalog_charge->ChargeModel == 'Tiered with Overage Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing') {
                         $catalog_charge->Uom = $rpc->UOM;
                         $catalog_charge->isTiered = true;
                     }
                     if ($catalog_charge->ChargeType != 'Usage' && ($catalog_charge->ChargeModel == 'Per Unit Pricing' || $catalog_charge->ChargeModel == 'Tiered Pricing' || $catalog_charge->ChargeModel == 'Volume Pricing')) {
                         $catalog_charge->Uom = $rpc->UOM;
                         $catalog_charge->quantifiable = true;
                         $catalog_charge->DefaultQuantity = isset($rpc->DefaultQuantity) ? $rpc->DefaultQuantity : "1";
                     }
                     // probably need special case for ChargeModel == Overage Pricing to show overage price
                     //MD New Lines to get detail for the individual charges
                     $result = $zapi->zQuery("select Id,Price,Currency,Tier,StartingUnit,EndingUnit,PriceFormat from ProductRatePlanChargeTier where ProductRatePlanChargeId='" . $catalog_charge->Id . "'");
                     $qChargeTiers = array();
                     $catalog_charge->chargeTiers = array();
                     if ($result->result != null) {
                         usort($result->result->records, "Amender::cmpTiers");
                         $qChargeTiers = $result->result->records;
                         if ($qChargeTiers != null) {
                             foreach ($qChargeTiers as $rpct) {
                                 $catalog_chargeTier = new Catalog_ChargeTier();
                                 $catalog_chargeTier->Id = $rpct->Id;
                                 $catalog_chargeTier->Price = $rpct->Price;
                                 $catalog_chargeTier->Currency = $rpct->Currency;
                                 $catalog_chargeTier->myCurrency = $rpct->Currency == $_SESSION['myCurrency'];
                                 $catalog_chargeTier->Tier = $rpct->Tier;
                                 $catalog_chargeTier->StartingUnit = $rpct->StartingUnit;
                                 $catalog_chargeTier->EndingUnit = $rpct->EndingUnit;
                                 $catalog_chargeTier->PriceFormat = $rpct->PriceFormat;
                                 array_push($catalog_charge->chargeTiers, $catalog_chargeTier);
                             }
                         }
                     }
                     //MD end new lines to get charge detail
                     array_push($catalog_rateplan->charges, $catalog_charge);
                 }
             }
             array_push($catalog_product->ratePlans, $catalog_rateplan);
         }
     }
     return $catalog_product;
 }
コード例 #3
0
ファイル: index.php プロジェクト: j0nbr0wn/zilla_heroku
function subscribeWithCurrentCart()
{
    global $messages;
    $userEmail = $_SESSION['userEmail'];
    $pmId = $_REQUEST['pmId'];
    $subRes = SubscriptionManager::subscribeWithCart($userEmail, $pmId, $_SESSION['cart']);
    if ($subRes == 'DUPLICATE_EMAIL') {
        addErrors(null, "This email address is already in use. Please choose another and re-submit.");
        return;
    }
    if ($subRes == 'INVALID_PMID') {
        addErrors(null, "There was an error processing this transaction. Please try again.");
        return;
    }
    $partnerLogin = false;
    $loginRes = LoginManager::loginAttempt($userEmail, $partnerLogin);
    $messages = $subRes;
}
コード例 #4
0
/**
 * Get language file text for url
 * 
 * @param $key the key of text file
 * @param $lg the language of text file
 */
function getLgFileTextForUrl($key, $lg = "")
{
    $lang_array = getLanguageFile($lg);
    if (array_key_exists($key, $lang_array)) {
        $a = str_replace(' ', '-', $lang_array[$key]);
        if (getDebugMode()) {
            echo "<p style='color:orange;'>GET2: " . str_replace('---', '-', $a) . "</p>";
        }
        return str_replace('---', '-', $a);
    } else {
        if (getDebugMode()) {
            addErrors("<u>getLgFileTextForUrl</u>", "No value for <b>''" . $key . "'</b>");
            echo "<p style='color:orange;'>GET2: Erreur</p>";
        }
        return "Erreur";
    }
}