Jump to content

 

dataspotgr

Member Since 04 Sep 2013
Offline Last Active Mar 02 2022 08:54 AM
-----

Topics I've Started

Checkout Page Php Function

09 August 2021 - 09:35 AM

Hi,
 
I would like your help with a problem that i have when i'm trying to execute a php function in the checkout page.
 
I have the code below which is added on the scripts.post.tpl file: 
<script>
    {if $runtime.controller == "checkout" && $runtime.mode == "checkout"}
        {assign var="event_id" value=100000|mt_rand:500000}
        {ds_fb_api_initiate_checkout($cart.total, $cart.amount, $cart_products, $event_id)}
    {/if}
</script>
 
The code and the function is running fine without any errors. The problem is that every time a customer change the payment or the shipping method, the function runs again and again after the ajax load.
 
Is there any other .tpl file that i can add my script in order to be executed only once, or maybe any way to stop if from running again after ajax calls?

Custom Block Content

23 February 2021 - 01:20 PM

Hi, i'm building a Custom Block and i could use some help on a problem that i have.

 

The block is working fine, but when i'm trying to add the "Content" tab on the block's settings it's not working. 

Actually, i want to be able to select some categories, and besad on the selected categories to do something in the front-end.

 

So, in order to select the categories i used this code:

$schema['ds_categories_scroller'] = array (
    'templates' => 'addons/ds_categories_scroller/blocks/ds_categories_scroller.tpl',
    'wrappers' => 'blocks/wrappers',
    'cache' => false,
    'content' => array(
        'items' => array(
            'type' => 'enum',
            'object' => 'categories',
            'items_function' => 'fn_get_categories',
            'remove_indent' => true,
            'hide_label' => true,
            'fillings' => array(
                'manually' => array(
                    'params' => array(
                        'plain' => true,
                        'simple' => false,
                        'group_by_level' => false,
                    ),
                    'picker' => 'pickers/categories/picker.tpl',
                    'picker_params' => array(
                        'multiple' => true,
                        'use_keys' => 'N',
                        'status' => 'A',
                        'positions' => true,
                    ),
                ),
            ),
        ),
    )
);

return $schema;

The problem now is that when i try to open the block's setting i got this cs-cart error:

"ErrorOops, something went wrong (Internal Server Error). Please try again."
 
Also i have those error in my php logs:
[23-Feb-2021 15:15:08 Europe/Athens] PHP Warning:  Illegal string offset 'items' in /home/designplus/public_html/staging/app/controllers/backend/block_manager.post.php on line 656
[23-Feb-2021 15:15:08 Europe/Athens] PHP Fatal error:  Uncaught Error: Cannot use string offset as an array in /home/designplus/public_html/staging/app/controllers/backend/block_manager.post.php:656
Stack trace:
#0 /home/designplus/public_html/staging/app/functions/fn.control.php(679): include()
#1 /home/designplus/public_html/staging/app/functions/fn.control.php(430): fn_run_controller('/home/designplu...', 'block_manager', 'update_block', '', '')
#2 /home/designplus/public_html/staging/instore.php(27): fn_dispatch()
#3 {main}
  thrown in /home/designplus/public_html/staging/app/controllers/backend/block_manager.post.php on line 656
[23-Feb-2021 15:15:08 Europe/Athens] PHP Fatal error:  ob_get_clean(): Cannot use output buffering in output buffering display handlers in /home/designplus/public_html/staging/app/Tygh/Ajax.php on line 139

I think there must be something with the 'type' => 'enum', because i tryied to change this for test perpuses with 'type' => 'text', and the setting opened normaly.

 


Check Product Promotion

26 November 2020 - 10:23 AM

Hi,

 

I'm trying to build a script in order to export some product data in a XML file.

 

I'm having a bit of trouble when i'm trying to export the sales price of a product if that product in in promotion.

 

Is there any in build CS-Cart function that can check if a product is in promotion and get me the correct sales price?


Notification Mail Not Sent

17 November 2020 - 08:49 AM

Hi,

 

I'm having having with some mail notifications.

When someone places an order and pays with credit card, the order lands in CS-Cart as Paid (Status "P").

 

After that, neither me, or the customer gets a notification mail that a new order have been placed. When an order comes, with any other payment method, the order lands as open and mail notification sents normaly.

 

Any suggestions on what i should look at to solve my problem?

 

Bellow you can see the code the from payment method, in case you think that its related to my issue. Seems fine to me, and works without no errors

<?php

use Tygh\Http;
use Tygh\Registry;

if (!defined('BOOTSTRAP')) { die('Access denied'); }

if (defined('PAYMENT_NOTIFICATION')) {

    if ($mode == 'notify') {
		
        $order_id = (strpos($_REQUEST['MerchantReference'], '_')) ? substr($_REQUEST['MerchantReference'], 0, strpos($_REQUEST['MerchantReference'], '_')) : $_REQUEST['MerchantReference'];
        $order_info = fn_get_order_info($order_id);
        $processor_data = fn_get_payment_method_data($order_info['payment_id']);

        $pp_response = array();
        $pp_response['transaction_id'] = $_REQUEST['TransactionId'];
        $pp_response['transaction_datetime'] = $_REQUEST['TransactionDateTime'];
        $pp_response['reason_text'] = $_REQUEST['ResponseDescription'];

        if ($_REQUEST['ResultCode'] == 0) {
            if ( $_REQUEST['StatusFlag'] == 'Success' && in_array($_REQUEST['ResponseCode'], array('00', '08', '10', '11', '16')) ) {

                $tran_ticket = db_get_field("SELECT data FROM ?:order_data WHERE type = 'E' AND order_id = ?i", $order_id);

                $cart_hashkey_str = $tran_ticket.';'.$processor_data['processor_params']['posid'].';'.$processor_data['processor_params']['acquirerid'].';'.$_REQUEST['MerchantReference'].';'.$_REQUEST['ApprovalCode'].';'.$_REQUEST['Parameters'].';'.$_REQUEST['ResponseCode'].';'.$_REQUEST['SupportReferenceID'].';'.$_REQUEST['AuthStatus'].';'.$_REQUEST['PackageNo'].';'.$_REQUEST['StatusFlag'];
				$cart_hashkey = strtoupper(hash_hmac('sha256', $cart_hashkey_str, $tran_ticket));

                if ($cart_hashkey == $_REQUEST['HashKey']) {
                    $pp_response['order_status'] = 'P';

                    db_query("DELETE FROM ?:order_data WHERE type = 'E' AND order_id = ?i", $order_id);

                    if (!empty($_REQUEST['SupportReferenceID'])) {
                        $pp_response['reason_text'] .= '; SupportReferenceID: ' . $_REQUEST['SupportReferenceID'];
                    }

                    if (!empty($_REQUEST['ApprovalCode'])) {
                        $pp_response['reason_text'] .= '; ApprovalCode: ' . $_REQUEST['ApprovalCode'];
                    }

                } else {
                    $pp_response['order_status'] = 'F';
                    $pp_response['reason_text'] .= 'Hash value is incorrect';
                }
            } elseif ($_REQUEST['StatusFlag'] == 'Failure') {
                $pp_response['order_status'] = 'F';

            } elseif ($_REQUEST['StatusFlag'] == 'Asynchronous') {
                $pp_response['order_status'] = 'O';
                $pp_response['reason_text'] .= '; Asynchronous';
            }

        } else {
            $pp_response['order_status'] = 'F';
        }

        if (fn_check_payment_script('winpay.php', $order_id)) {
            fn_finish_payment($order_id, $pp_response, false);
        }

        fn_order_placement_routines('route', $order_id);
    } elseif ($mode == 'cancel') {

        if (!empty($_SESSION['stored_piraeus_orderid'])) {
            $order_id = $_SESSION['stored_piraeus_orderid'];
            unset($_SESSION['stored_piraeus_orderid']);
        } else {
            fn_order_placement_routines('checkout_redirect');
        }

        $pp_response['order_status'] = 'N';
        $pp_response["reason_text"] = __('text_transaction_cancelled');

        if (fn_check_payment_script('piraeus.php', $order_id)) {
            fn_finish_payment($order_id, $pp_response, false);
        }

        fn_order_placement_routines('route', $order_id);
    }

} else {

    if (!empty($payment_info['installments'])) {

        if (Registry::get('addons.winpay.show_all_installments') == 'Y') {
			$installment = db_get_row('SELECT * FROM ?:winpay_installments WHERE installment_id = ?i', $payment_info['installment_id']);
			$installment['installments'] = $payment_info['installments'];
		} else {
			$installment = db_get_row('SELECT * FROM ?:winpay_installments WHERE installment_id = ?i', $payment_info['installments']);
		}
		$ab_interest = $order_info['total'] * ($installment['p_interest']/100) + $installment['a_interest'];
		$ab_total = $order_info['total'] + $ab_interest;
		$ab_payment_surcharge = $ab_interest + $order_info['payment_surcharge'];
		db_query("UPDATE ?:orders SET ?u WHERE order_id = ?i", array('total' => $ab_total, 'payment_surcharge' => $ab_payment_surcharge), $order_info['order_id']);
		$order_info['total'] = $ab_total;
		$period = $installment['installments'];

		$_data = array (
			'order_id' => $order_id,
			'type' => 'P', //payment information
			'data' => fn_encrypt_text(serialize(array('installments' => $period))),
		);

		db_query("REPLACE INTO ?:order_data ?e", $_data);

    } else {

		$period = 0;

    }

	$ticketing_data = Array (
        'AcquirerId' => $processor_data['processor_params']['acquirerid'],
        'MerchantId' => $processor_data['processor_params']['merchantid'],
        'PosId' => $processor_data['processor_params']['posid'],
        'Username' => $processor_data['processor_params']['username'],
        'Password' => md5($processor_data['processor_params']['password']),
        'RequestType' => $processor_data['processor_params']['requesttype'],
        'CurrencyCode' => $processor_data['processor_params']['currencycode'],
        'MerchantReference' => (($order_info['repaid']) ? ($order_id . '_' . $order_info['repaid']) : $order_id),
        'Amount' => $order_info['total'],
        'Installments' => $period,
        'Bnpl' => 0,
        'ExpirePreauth' => (($processor_data['processor_params']['requesttype'] == '00') ? $processor_data['processor_params']['expirepreauth'] : '0'),
        'Parameters' => '',
        'MyBank' => (isset($processor_data['processor_params']['mybank']) && $processor_data['processor_params']['mybank'] == 'Y') ? 'yes' : 'no',
    );

    $str = <<<EOT
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<IssueNewTicket xmlns="http://piraeusbank.gr/paycenter/redirection">
<Request>
EOT;
    $str .= fn_array_to_xml($ticketing_data);
    $str .= <<<EOT
</Request>
</IssueNewTicket>
</soap:Body>
</soap:Envelope>
EOT;
    $str = str_replace(array("\t", "\n", "\r"), '', $str);

    $response_data = Http::post("https://paycenter.piraeusbank.gr/services/tickets/issuer.asmx", $str, array(
        'headers' => array(
            'Content-type: text/xml; charset=utf-8',
            'SOAPAction: http://piraeusbank.gr/paycenter/redirection/IssueNewTicket'
        )
    ));

    $resultcode = true;
    $pp_response = array();

    if (strpos($response_data, '<ResultCode') !== false) {
        if (preg_match('!<ResultCode[^>]*>([^>]+)</ResultCode>!', $response_data, $matches)) {
            $resultcode = $matches[1];
        }
    }

    if ($resultcode == "0") {

        if (strpos($response_data, '<TranTicket') !== false) {
            if (preg_match('!<TranTicket[^>]*>([^>]+)</TranTicket>!', $response_data, $matches)) {
                $data = array (
                    'order_id' => $order_id,
                    'type' => 'E',
                    'data' => $matches[1],
                );
                db_query("REPLACE INTO ?:order_data ?e", $data);
            }
        }

        $post_url = 'https://paycenter.piraeusbank.gr/redirection/pay.aspx';

        $post_data = array (
            'AcquirerId' => $processor_data['processor_params']['acquirerid'],
            'MerchantId' => $processor_data['processor_params']['merchantid'],
            'PosId' => $processor_data['processor_params']['posid'],
            'User' => $processor_data['processor_params']['username'],
            'LanguageCode' => $processor_data['processor_params']['languagecode'],
            'MerchantReference' => (($order_info['repaid']) ? ($order_id . '_' . $order_info['repaid']) : $order_id),
            'ParamBackLink' => ""
        );

        $_SESSION['stored_piraeus_orderid'] = $order_id;

        fn_create_payment_form($post_url, $post_data, 'Piraeus server');
    exit;

    } else {
        $pp_response['order_status'] = 'F';
        $pp_response["ResultCode"] = $resultcode;

        if (strpos($response_data, '<ResultDescription') !== false) {
            if (preg_match('!<ResultDescription[^>]*>([^>]+)</ResultDescription>!', $response_data, $matches)) {
                $pp_response["reason_text"] = $matches[1];
            }
        }
    }


}