Пример #1
0
 public function Render()
 {
     // Get Category ID
     $catId = SMEnvironment::GetQueryValue("SMShopCategory");
     // Load products
     $ds = new SMDataSource("SMShopProducts");
     $where = $catId !== null && $catId !== "Overview" ? "CategoryId = '" . $ds->Escape($catId) . "'" : "";
     $products = $ds->Select("*", $where);
     if ($catId !== "Overview" && count($products) > 0 && $products[0]["CategoryId"] !== $catId) {
         // SEO: Make CategoryId case sensitive
         $products = array();
     }
     // Add additional data
     foreach ($products as $prod) {
         // Notice: Data in DataSource uses lowercase keys.
         // Therefore place holders in template, to which data is mapped,
         // will be transformed to lowercase keys (see lowerCasePlaceHolders(..)).
         // Entries added below therefore also have to use lowercase keys.
         if ($prod["Vat"] === "" || (double) $prod["Vat"] === 0.0) {
             $prod["fullprice"] = $prod["Price"];
         } else {
             $prod["fullprice"] = (string) round((double) $prod["Price"] + (double) $prod["Price"] * ((double) $prod["Vat"] / 100), 2);
         }
         $prod["buy"] = $this->lang->GetTranslation("Buy");
         $prod["readmore"] = $this->lang->GetTranslation("ReadMore");
     }
     // Set page title
     $title = $catId === "Overview" ? $this->lang->GetTranslation("Overview") : (count($products) > 0 ? $products[0]["Category"] : $this->lang->GetTranslation("NoProducts"));
     $this->context->GetTemplate()->ReplaceTag(new SMKeyValue("Title", $title));
     $output = "<h1>" . $title . "</h1>";
     // Load view and populate data
     $extPath = SMExtensionManager::GetExtensionPath($this->context->GetExtensionName());
     SMEnvironment::GetMasterTemplate()->RegisterResource(SMTemplateResource::$StyleSheet, $extPath . "/JSShop/Views/ProductList.css", true);
     $view = new SMTemplate($extPath . "/JSShop/Views/ProductList.html");
     $this->lowerCasePlaceHolders($view);
     // Data in DataSource uses lowercase keys, so place holders must use the same casing
     $view->ReplaceTagsRepeated("Products", $products);
     // Insert images
     $images = array();
     foreach ($products as $prod) {
         if ($prod["Images"] === "") {
             continue;
         }
         $images = array();
         foreach (explode(";", $prod["Images"]) as $src) {
             $images[] = new SMKeyValueCollection();
             $images[count($images) - 1]["image"] = $src;
         }
         $view->ReplaceTagsRepeated("Images" . $prod["Id"], $images);
     }
     // Add JSShop init script
     $output .= "\n\t\t<script type=\"text/javascript\">\n\n\t\tJSShop.Initialize(function()\n\t\t{\n\t\t\tJSShop.Presenters.ProductList.Initialize(document.getElementById('JSShopProductList'));\n\t\t});\n\n\t\t</script>\n\t\t";
     // Return result
     return $output . $view->GetContent();
 }
Пример #2
0
{
    $ds = new SMDataSource("SMShopOrders");
    $orders = $ds->Select("*", "Id = '" . $ds->Escape($orderId) . "'");
    if (count($orders) !== 1) {
        header("HTTP/1.1 500 Internal Server Error");
        echo "Order with ID '" . $orderId . "' could not be found";
        exit;
    }
    return $orders[0];
}
// Payment handling.
// Step 1: User is redirected to payment form.
// Step 2: PSP invokes callback to let us know payment was received.
$operation = SMEnvironment::GetQueryValue("PaymentOperation");
if ($operation === null) {
    $orderId = SMEnvironment::GetQueryValue("OrderId");
    $order = getOrder($orderId);
    if ($order["State"] !== "Initial") {
        header("HTTP/1.1 500 Internal Server Error");
        echo "Order with ID '" . $orderId . "' has already been processed";
        exit;
    }
    $amount = (int) round(((double) $order["Price"] + (double) $order["Vat"]) * 100);
    // Amount in smallest possible unit (e.g. USD 10095 = USD 100.95)
    $currency = $order["Currency"];
    $continueUrl = SMEnvironment::GetExternalUrl();
    $continueUrl .= SMAttributes::GetAttribute("SMShopReceiptPage") !== null && SMAttributes::GetAttribute("SMShopReceiptPage") !== "" ? "/" . SMAttributes::GetAttribute("SMShopReceiptPage") : "";
    $callbackUrl = SMEnvironment::GetExternalUrl() . "/" . SMExtensionManager::GetCallbackUrl(SMExtensionManager::GetExecutingExtension(), "Callbacks/Payment") . "&PaymentOperation=Auth";
    $p = PSP::GetPaymentProvider($order["PaymentMethod"]);
    $p->RedirectToPaymentForm($orderId, $amount, $currency, $continueUrl, $callbackUrl);
} else {
Пример #3
0
 public function Render()
 {
     if (SMEnvironment::GetQueryValue("SMShopEditProducts") !== null) {
         if (SMAuthentication::Authorized() === false) {
             SMExtensionManager::ExecuteExtension(SMExtensionManager::GetDefaultExtension());
         }
         $frm = new SMShopFrmShop($this->context);
         return $frm->Render();
     }
     if (SMEnvironment::GetQueryValue("SMShopBasket") !== null) {
         $frm = new SMShopFrmBasket($this->context);
         return $frm->Render();
     } else {
         $frm = new SMShopFrmProducts($this->context);
         return $frm->Render();
     }
 }