Example #1
0
 public function Render()
 {
     $extPath = SMExtensionManager::GetExtensionPath($this->context->GetExtensionName());
     SMEnvironment::GetMasterTemplate()->RegisterResource(SMTemplateResource::$StyleSheet, $extPath . "/JSShop/Views/Basket.css", true);
     $output = "\n\t\t<div id=\"" . $this->context->GetExtensionName() . "BasketContainer\"></div>\n\t\t<br>\n\t\t<div id=\"" . $this->context->GetExtensionName() . "OrderFormContainer\"></div>\n\n\t\t<script type=\"text/javascript\">\n\n\t\tJSShop.Initialize(function()\n\t\t{\n\t\t\tvar b = new JSShop.Presenters.Basket();\n\t\t\tb.Render(document.getElementById(\"" . $this->context->GetExtensionName() . "BasketContainer\"));\n\n\t\t\tvar o = new JSShop.Presenters.OrderForm();\n\t\t\to.Render(document.getElementById(\"" . $this->context->GetExtensionName() . "OrderFormContainer\"));\n\t\t});\n\n\t\t</script>\n\t\t";
     return $output;
 }
Example #2
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();
 }
Example #3
0
// 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 {
    if ($operation === "Auth") {
        $data = PSP::GetCallbackData();
        // Securely obtain data passed to callback
        $transactionId = $data["TransactionId"];
        // String
        $orderId = $data["OrderId"];
        // String
        //$amount = $data["Amount"];				// Integer
        //$currency = $data["Currency"];			// String
        $order = getOrder($orderId);
        $order["TransactionId"] = $transactionId;
        $order["State"] = "Authorized";
Example #4
0
 public function PreTemplateUpdate()
 {
     if ($this->smMenuExists === true) {
         $menuItem = SMMenuManager::GetInstance()->GetChild("SMMenuContent");
         if ($menuItem !== null) {
             $menuItem->AddChild(new SMMenuItem($this->name, $this->getTranslation("Products"), SMExtensionManager::GetExtensionUrl($this->name) . "&SMShopEditProducts"));
         }
     }
 }
Example #5
0
function SMShopFinalizeNewOrder(SMKeyValueCollection $order)
{
    $mailAddress = $order["Email"];
    $title = SMAttributes::GetAttribute("SMShopOrderConfirmationMailTitle");
    $content = SMAttributes::GetAttribute("SMShopOrderConfirmationMailContent");
    if ($content === null || $content === "" || SMStringUtilities::Validate($mailAddress, SMValueRestriction::$EmailAddress) === false) {
        return;
    }
    $lang = new SMLanguageHandler(SMExtensionManager::GetExecutingExtension());
    $eDs = new SMDataSource("SMShopOrderEntries");
    $pDs = new SMDataSource("SMShopProducts");
    // Order details
    $entries = $eDs->Select("*", "OrderId = '" . $eDs->Escape($order["Id"]) . "'");
    $products = null;
    $orderDetails = "";
    foreach ($entries as $entry) {
        $products = $pDs->Select("*", "Id = '" . $pDs->Escape($entry["ProductId"]) . "'");
        if (count($products) === 0) {
            header("HTTP/1.1 500 Internal Server Error");
            echo "Product could not be found";
            exit;
        }
        $orderDetails .= $orderDetails !== "" ? "<br>" : "";
        $orderDetails .= $entry["Units"] . " x " . $products[0]["Title"] . ", " . $order["Currency"] . " " . number_format(((int) $entry["Units"] * (double) $entry["UnitPrice"] - (double) $entry["Discount"]) * ((double) $entry["Vat"] / 100 + 1), 2, $lang->GetTranslation("DecimalSeparator"), "");
    }
    // Shipping expense
    if ($order["ShippingExpense"] !== "0") {
        $orderDetails .= "<br>";
        $orderDetails .= ($order["ShippingMessage"] !== "" ? $order["ShippingMessage"] : $lang->GetTranslation("Shipping")) . ", " . $order["Currency"] . " " . number_format((double) $order["ShippingExpense"] + (double) $order["ShippingVat"], 2, $lang->GetTranslation("DecimalSeparator"), "");
    }
    // Mail content - replace place holders
    $content = str_replace("{Company}", $order["Company"], $content);
    $content = str_replace("{FirstName}", $order["FirstName"], $content);
    $content = str_replace("{LastName}", $order["LastName"], $content);
    $content = str_replace("{Address}", $order["Address"], $content);
    $content = str_replace("{ZipCode}", $order["ZipCode"], $content);
    $content = str_replace("{City}", $order["City"], $content);
    $content = str_replace("{Phone}", $order["Phone"], $content);
    $content = str_replace("{Email}", $order["Email"], $content);
    $content = str_replace("{Message}", nl2br($order["Message"]), $content);
    $content = str_replace("{AltCompany}", $order["AltCompany"], $content);
    $content = str_replace("{AltFirstName}", $order["AltFirstName"], $content);
    $content = str_replace("{AltLastName}", $order["AltLastName"], $content);
    $content = str_replace("{AltAddress}", $order["AltAddress"], $content);
    $content = str_replace("{AltZipCode}", $order["AltZipCode"], $content);
    $content = str_replace("{AltCity}", $order["AltCity"], $content);
    $content = str_replace("{DeliveryCompany}", $order["AltAddress"] !== "" ? $order["AltCompany"] : $order["Company"], $content);
    // Use AltCompany (which is optional) only if AltAddress is set
    $content = str_replace("{DeliveryFirstName}", $order["AltFirstName"] !== "" ? $order["AltFirstName"] : $order["FirstName"], $content);
    $content = str_replace("{DeliveryLastName}", $order["AltLastName"] !== "" ? $order["AltLastName"] : $order["LastName"], $content);
    $content = str_replace("{DeliveryAddress}", $order["AltAddress"] !== "" ? $order["AltAddress"] : $order["Address"], $content);
    $content = str_replace("{DeliveryZipCode}", $order["AltZipCode"] !== "" ? $order["AltZipCode"] : $order["ZipCode"], $content);
    $content = str_replace("{DeliveryCity}", $order["AltCity"] !== "" ? $order["AltCity"] : $order["City"], $content);
    $content = str_replace("{OrderId}", $order["Id"], $content);
    $content = str_replace("{Currency}", $order["Currency"], $content);
    $content = str_replace("{Vat}", number_format((double) $order["Vat"], 2, $lang->GetTranslation("DecimalSeparator"), ""), $content);
    $content = str_replace("{Price}", number_format((double) $order["Price"] + (double) $order["Vat"], 2, $lang->GetTranslation("DecimalSeparator"), ""), $content);
    $content = str_replace("{Weight}", number_format((double) $order["Weight"], 2, $lang->GetTranslation("DecimalSeparator"), ""), $content);
    $content = str_replace("{WeightUnit}", $order["WeightUnit"], $content);
    $content = str_replace("{ShippingExpense}", number_format((double) $order["ShippingExpense"], 2, $lang->GetTranslation("DecimalSeparator"), ""), $content);
    $content = str_replace("{ShippingVat}", number_format((double) $order["ShippingVat"], 2, $lang->GetTranslation("DecimalSeparator"), ""), $content);
    $content = str_replace("{ShippingMessage}", $order["ShippingMessage"], $content);
    $content = str_replace("{DateYear}", date("Y"), $content);
    $content = str_replace("{DateMonth}", date("m"), $content);
    $content = str_replace("{DateDay}", date("d"), $content);
    $content = str_replace("{OrderDetails}", $orderDetails, $content);
    $mail = new SMMail();
    $mail->AddRecipient($mailAddress);
    $mail->SetSubject($title !== null && $title !== "" ? $title : $lang->GetTranslation("ConfirmationTitle"));
    $mail->SetContent($content);
    if (SMAttributes::GetAttribute("SMShopEmail") !== null && SMAttributes::GetAttribute("SMShopEmail") !== "" && SMStringUtilities::Validate(SMAttributes::GetAttribute("SMShopEmail"), SMValueRestriction::$EmailAddress) === true) {
        $mail->SetSender(SMAttributes::GetAttribute("SMShopEmail"));
    }
    $mail->Send();
}