/**
  * Returns all available shipping methods for the current cart
  * together with the appropriate prices
  *
  * Sample return
  * return array(
  *  'flat_rate_shipping' => 'Flat rate shipping 10$'
  * , 'ups__01' => 'UPS Domestic bla bla 5$'
  * , 'ups__65' => 'UPS International saver 4$'
  * )
  */
 public function getAvailableShippingMethodsAndTheirPrices($module_srl, Cart $cart)
 {
     $cache_key = 'available_shipping_' . $module_srl . '_' . $cart->cart_srl;
     $available_shipping_methods = self::$cache->get($cache_key);
     if (!$available_shipping_methods) {
         $shop_info = new ShopInfo($module_srl);
         $active_shipping_methods = $this->getActiveShippingMethods($module_srl);
         $available_shipping_methods = array();
         foreach ($active_shipping_methods as $shipping_method) {
             $available_variants = $shipping_method->getAvailableVariants($cart);
             foreach ($available_variants as $variant) {
                 if (!$variant->price) {
                     $key = "";
                     $value = $variant->display_name . ' - ' . $variant->variant_display_name;
                 } else {
                     $key = $variant->name;
                     if ($variant->variant) {
                         $key .= '__' . $variant->variant;
                     }
                     $value = $variant->display_name;
                     if ($variant->variant) {
                         $value .= ' - ' . $variant->variant_display_name;
                     }
                     $value .= ' - ' . ShopDisplay::priceFormat($variant->price, $shop_info->getCurrencySymbol());
                 }
                 $available_shipping_methods[$key] = $value;
             }
         }
         self::$cache->set($cache_key, $available_shipping_methods);
     }
     return $available_shipping_methods;
 }
Пример #2
0
 /**
  * Returns HTML code for a textarea form field that supports multiple languages
  *
  * @param      $input_name
  * @param null $input_id
  * @param null $input_value
  * @param      $input_style
  * @param      $input_class
  * @param      $label_value
  * @param      $label_class
  * @param      $container_class
  * @param      $rows
  * @param      $cols
  * @return string
  */
 public static function multiLanguageTextarea($input_name, $input_id = NULL, $input_value = NULL, $input_style, $input_class, $label_value, $label_class, $container_class, $rows, $cols)
 {
     return ShopDisplay::multiLanguageFormField('textarea', $input_name, $input_id, $input_value, $input_style, $input_class, $label_value, $label_class, $container_class, $rows, $cols);
 }
Пример #3
0
        /**
         * print PDF order
         * @param Order $order
         */
        private function printPDFOrder(Order $order){

            global $lang;
            $product_items = $order->getProducts();
            $shop = new ShopInfo($this->module_srl);
            $this->model->includeTCPDF();

            // create new PDF document
            $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, TRUE, 'UTF-8', FALSE);

            // set document information
            $pdf->SetCreator($shop->getShopTitle());
            $pdf->SetTitle(sprintf($lang->order_with_number, $order->order_srl));
            $pdf->SetSubject(sprintf($lang->order_with_number, $order->order_srl));

            $pdf->setPrintHeader(FALSE);
            $pdf->setPrintFooter(FALSE);

            // set font
            $pdf->SetFont('dejavusans', '', 10);

            // add a page
            $pdf->AddPage();


            // create HTML content
            $html = '
            <div style="float:left; text-align: center;">'.$shop->getShopTitle().'</div>
            <h1>'.sprintf($lang->order_with_number, $order->order_srl).'</h1>
            <p></p>
            Order date: '.zdate($order->regdate,'d-M-y').'
            <p></p><h3>'.$lang->shipping_address.'</h3>'.$order->shipping_address.'
            <p></p><h3>'.$lang->billing_address.'</h3>'.$order->billing_address.'
            <p></p><h3>'.$lang->payment_method_used.'</h3>'.ucwords(str_replace('_', ' ', $order->payment_method)).'
            <p></p><h3>'.$lang->shipping_method_used.'</h3>'.ucwords(str_replace('_', ' ', $order->shipping_method)).'
            <p></p><h3>'.$lang->items_ordered.'</h3></br>';

            // output the HTML content
            $pdf->writeHTML($html, TRUE, FALSE, TRUE, FALSE, '');

            // Colors, line width and bold font
            $pdf->SetFillColor(38, 74, 108);
            $pdf->SetTextColor(255);
            $pdf->SetDrawColor(38, 74, 108);
            $pdf->SetLineWidth(0.3);
            $pdf->SetFont('', 'B');
            // Header
            $w = array(15, 70, 20, 45, 45);
            $header= $header = array($lang->product_no_dot, $lang->title, $lang->quantity, $lang->price, $lang->subtotal);
            $num_headers = count($header);
            for($i = 0; $i < $num_headers; ++$i) {
                $pdf->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
            }
            $pdf->Ln();
            // Color and font restoration
            $pdf->SetFillColor(224, 235, 255);
            $pdf->SetTextColor(0);
            $pdf->SetFont('');
            // Data
            $fill = 0;
            $i = 0;
            foreach($product_items as $product){
                $i++;
                $pdf->Cell($w[0], 6, $i, 'LR', 0, 'C', $fill);
                $pdf->Cell($w[1], 6, $product->getTitle(), 'LR', 0, 'L', $fill);
                $pdf->Cell($w[2], 6, $product->getQuantity(), 'LR', 0, 'R', $fill);
                $pdf->Cell($w[3], 6, ShopDisplay::priceFormat($product->getPrice(), $shop->getCurrencySymbol()), 'LR', 0, 'R', $fill);
                $pdf->Cell($w[4], 6, ShopDisplay::priceFormat($product->getPrice() * $product->getQuantity(), $shop->getCurrencySymbol()), 'LR', 0, 'R', $fill);
                $pdf->Ln();
                $fill=!$fill;
            }

            $pdf->Cell(array_sum($w) - $w[4], 6, $lang->total, 1, 0, 'R',$fill);
            $pdf->Cell($w[4], 6, ShopDisplay::priceFormat($order->getTotalBeforeDiscount(), $shop->getCurrencySymbol()), 1, 0, 'R',$fill);
            $fill=!$fill;
            $pdf->Ln();

            if($order->getDiscountAmount()){
                $pdf->Cell(array_sum($w) - $w[4], 6, $lang->discount, 1, 0, 'R',$fill);
                $pdf->Cell($w[4], 6, ShopDisplay::priceFormat(-1 * $order->getDiscountAmount(), $shop->getCurrencySymbol()), 1, 0, 'R',$fill);
                $fill=!$fill;
                $pdf->Ln();
            }

            if($order->getShippingMethodName()){
                $pdf->Cell(array_sum($w) - $w[4], 6, $lang->shipping, 1, 0, 'R',$fill);
                $pdf->Cell($w[4], 6, ShopDisplay::priceFormat($order->getShippingCost(), $shop->getCurrencySymbol()), 1, 0, 'R',$fill);
                $fill=!$fill;
                $pdf->Ln();
            }

            $pdf->SetFont('', 'B');
            $pdf->Cell(array_sum($w) - $w[4], 6, $lang->grand_total, 1, 0, 'R',$fill);
            $pdf->Cell($w[4], 6, ShopDisplay::priceFormat($order->getTotal(), $shop->getCurrencySymbol()), 1, 0, 'R',$fill);
            $fill=!$fill;
            $pdf->Ln();
            $pdf->SetFont('');

            if($shop->showVAT()){
                $pdf->Cell(array_sum($w) - $w[4], 6, $lang->taxes, 1, 0, 'R',$fill);
                $pdf->Cell($w[4], 6, ShopDisplay::priceFormat($order->getVAT(), $shop->getCurrencySymbol()), 1, 0, 'R',$fill);
                $fill=!$fill;
                $pdf->Ln();
            }

            $pdf->Cell(array_sum($w), 0, '', 'T');


            //Close and output PDF document
            $pdf->Output(sprintf($lang->order_with_number, $order->order_srl), 'I');
        }
	/**
	 * Calls the Paypal API for executing the payment
	 *
	 * @param Cart $cart
	 * @param      $error_message
	 * @return bool|mixed
	 */
	public function processPayment(Cart $cart, &$error_message)
    {
        $payer_id = Context::get('payer_id');
        $token = Context::get('token');

        $paypalAPI = new PaypalExpressCheckoutAPI($this->gateway_api == PaypalExpressCheckout::LIVE_URL
			, $this->api_username
            , $this->api_password
            , $this->signature
        );

        // Get shop info
        $shop_info = new ShopInfo($cart->module_srl);

        // Prepare cart info
        $items = $this->getItemsFromCart($cart);

        $paypalAPI->doExpressCheckoutPayment($token
            , $payer_id
            , $items
            , ShopDisplay::numberFormat($cart->getItemTotal())
            , 0
            , ShopDisplay::numberFormat($cart->getShippingCost())
            , ShopDisplay::numberFormat($cart->getTotal())
            , $shop_info->getCurrency()
        );

        if(!$paypalAPI->success)
        {
            $error_message = $paypalAPI->error_message;
            return FALSE;
        }
        else
        {
            Context::set('payment_status', $paypalAPI->payment_status);
            return TRUE;
        }
    }
Пример #5
0
 private static function sendNewOrderMailToAdministrator($shop, $order)
 {
     // Don't send anything if admin email is not configured
     if (!$shop->getEmail()) {
         ShopLogger::log("Failed to send order email to admin for order #{$order->order_srl}; Admin email is not configured");
         return;
     }
     global $lang;
     $admin_email_subject = sprintf($lang->admin_order_email_subject, $order->client_name, ShopDisplay::priceFormat($order->total, $shop->getCurrencySymbol()));
     Context::set('email_order', $order);
     $oTemplateHandler = TemplateHandler::getInstance();
     $order_content = $oTemplateHandler->compile('./modules/shop/tpl', 'order_email.html');
     $admin_email_content = sprintf($lang->admin_order_email_content, getFullSiteUrl('', 'act', 'dispShopToolViewOrder', 'order_srl', $order->order_srl), $order->order_srl, $order_content);
     $oMail = new Mail();
     $oMail->setTitle($admin_email_subject);
     $oMail->setContent($admin_email_content);
     $oMail->setSender($shop->getShopTitle(), $shop->getShopEmail());
     $oMail->setReceiptor(false, $shop->getEmail());
     $oMail->send();
 }