X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Third Party Add-Ons for X-Cart 4 (https://forum.x-cart.com/forumdisplay.php?f=45)
-   -   altered carts OnSale mod for php 7+ (https://forum.x-cart.com/showthread.php?t=76935)

keystone 04-25-2019 10:27 AM

altered carts OnSale mod for php 7+
 
I bought the unencrypted files from AlteredCart for the OnSale mod when Bill was closing up shop, did anyone else do that so they could update the files for php7+? I don't have enough coding knowledge to know what I'm doing and was looking to see if anyone has it working already.
Thanks.

elmirage001 04-25-2019 12:18 PM

Re: altered carts OnSale mod for php 7+
 
I use AC's Cash Rewards and had an issue with PHP 7.x because AC Cash Rewards uses mysql_real_escape_string() which is not supported in PHP 7.x.

Check your log files to see if you have a PHP error for mysql_real_escape_string()

If yes maybe the following will help.

Steve pointed me to X-Cart's func_addslashes($html_escape) so I added the following to func.core.php

After:
Code:

function func_get_internal_banners($type)
{
    global $sql_tbl;

    if (empty($type)) {
        return;
  }

    $return = func_query("SELECT * FROM $sql_tbl[internal_banners] WHERE type='$type'");
    return $return;
}


Add:
Code:

function mysql_real_escape_string($html_escape)
{
  return func_addslashes($html_escape);
}


keystone 04-25-2019 12:50 PM

Re: altered carts OnSale mod for php 7+
 
thanks for the reply elmirage but i didn't even get that far yet, I was just wondering if anyone one had done it successfully yet.

Thomasb134 04-25-2019 08:26 PM

Re: altered carts OnSale mod for php 7+
 
I can't offer any direct advice with porting the AC OnSale module. But I know what you are up against. I'm nearly done with doing that to Bill's Checkout One (one page checkout) module. It's been a horrible experience but I think I've finally beaten it.

You can get a feel for some issues by testing the module's php files using these online PH7 compatibility tools:
https://phpcodechecker.com/
https://www.piliapp.com/php-syntax-check/


As mentioned in the previous post, you'll need to recreate the missing mysql_real_escape_string() function. And I suspect there will be some instances of the deleted mysql_query() function (removed in PHP7). It can be replaced with db_query().

Be sure to work from a development store because it may take awhile to sort through all the problems that come up.

No doubt there will be more to it than these things. But if you post about the issues that pop up then maybe the community can walk you through it.

BTW, I'm using XC's Onsale Module (X-HotProducts) and it is working in my 4.4.5 store with PH7, no patches.

elmirage001 04-25-2019 09:34 PM

Re: altered carts OnSale mod for php 7+
 
I second Thomas's recommendation of X-Cart's Onsale module. I've been using it for a few years now. Our sales change a lot so I'm putting things on sale and taking others off sale all the time. I got tired of the labor intensive process very quickly so I came up with the following.

Final version is the last post.

https://forum.x-cart.com/showthread.php?t=75341

Paul

keystone 05-24-2019 01:33 PM

Re: altered carts OnSale mod for php 7+
 
The problems I have with x-carts Onsale module are that you can't do nearly the types of sales such as buy 2 get one free, spend x get x discount on the order, etc. I guess it works ok if you just want to do straight discounts on individual products but AC onsale mod spoiled me I think.

Thomas, thanks for the links to the tools, I'll give them a shot. I added the code to the func.core.php file as a start so I'll see how it goes.

elmirage001 05-24-2019 02:06 PM

Re: altered carts OnSale mod for php 7+
 
jQuery was updated in 4.7.11 and I had to update a section of Bill's code in his Cash Rewards. You may need to check his code for any thing deprecated.

For example Bill used .live but it is now deprecated and I had to change as shown below.
From:
Code:

// Cash Rewards :: www.alteredcart.com //
$('.unsetCashRewards').live('click', this._unsetRewards);
$('.applyRewardButton').live('click', this._applyRewards);
// Cash Rewards :: www.alteredcart.com //

To:
Code:

// Cash Rewards :: www.alteredcart.com //
$(document).on('click','.unsetCashRewards',this._unsetRewards);
$(document).on('click','.applyRewardButton',this._applyRewards);
// Cash Rewards :: www.alteredcart.com //


I didn't know initially that .live was the issue. I found by a process of elimination (the long and painful method) :-)

This page showed me how to fix the issue. http://api.jquery.com/live/

Hopefully you won't have any jQuery issues to worry about. Good luck!

Paul

keystone 06-03-2019 11:07 AM

Re: altered carts OnSale mod for php 7+
 
Using the recommended PHP Code Checker I have this issue...

session_register is depreciated

I have this code
Code:

// Page Control //
x_session_register('page_control');

if (!$page_control && empty($change)){
        $page_control = 'overview';
}

if (!empty($change)){
        $page_control = $change;
}


I see that the recommended fix is
Two things that came to my mind:

Quote:

Using global variables is not good anyway, find a way to avoid them.
You can still set variables with $_SESSION['var'] = "value".

Can someone show me how to fix this one? I'm not sure how, once I see and example I should be able to fix the rest of the instances on my own (hopefully)
Thanks.

cflsystems 06-03-2019 11:46 AM

Re: altered carts OnSale mod for php 7+
 
x_session_register is XC function not PHP function. It is declared in include/sessions.php I believe. There is nothing to fix.

keystone 06-03-2019 12:35 PM

Re: altered carts OnSale mod for php 7+
 
ah, ok. Thanks.

keystone 06-06-2019 01:23 PM

Re: altered carts OnSale mod for php 7+
 
I did get this error with the php code checker...

Quote:

Warning: There is 1 array declaration that contains a single equal sign '=' instead of '=>':


Code:

array(func_query_first_cell("SELECT categoryid FROM $sql_tbl[products_categories] WHERE productid='".$product['productid']."' AND main='Y'"))

It that really an error or is the code ok?

keystone 06-07-2019 10:33 AM

Re: altered carts OnSale mod for php 7+
 
So i've made a few changes to the OnSale mod to try and get it in line with php7.2 and here one I'm stuck on... I currently have
Code:

                if (db_query("UPDATE xcart_onsale SET begin='$begin', end='$end', saletype='$saletype', criteria='".addslashes(serialize($product_criteria))."', coupon_code='$coupon_code', uses='$times_to_use', home_display='$home_display', onsale_product_display='$onsale_product_display', onsale_display='$onsale_display', per_customer='$per_customer', productids='$productids', catids='$catids', provider='$login', status='".mysqli_real_escape_string($sale_status)."' WHERE onsaleid='$edit_update'")){
and get the error
Quote:

Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given in /home/keyston1/public_html.dev/admin/onsale.php on line 677


Apparently I need to add the connection to the db in the mysqli function part
Code:

.mysqli_real_escape_string($my_connection,$sale_status)
I'm not sure what $my_connection should actually say...?
and am I headed in the right direction?
Thanks.

Thomasb134 06-07-2019 10:56 AM

Re: altered carts OnSale mod for php 7+
 
Don't update the original code to use mysqli_real_escape_string(). Instead, leave the old code as-is and recreate the missing mysql_real_escape_string() function that was removed in PHP7.

The details on how to do it are explained here:
https://forum.x-cart.com/showpost.php?p=410661&postcount=10
.

keystone 06-07-2019 11:57 AM

Re: altered carts OnSale mod for php 7+
 
I notice that post says if it is the ionCube version than that fix won't help. The instructions in the Bills unencrypted source code says that
Quote:

The licensing for the module uses ionCube

does that mean I can't use the fix?

Thomasb134 06-07-2019 12:12 PM

Re: altered carts OnSale mod for php 7+
 
In the Final weeks of Bill closing down his business he provided unencrypted source code (ioncube removed) to existing customers for a small fee. It was a limited time offer.

If that is what you have then you can ignore the ioncube license comment in his instructions since it does not apply.

keystone 06-07-2019 12:13 PM

Re: altered carts OnSale mod for php 7+
 
Looks like it may have worked, stand by.

keystone 07-05-2019 09:47 AM

Re: altered carts OnSale mod for php 7+
 
I'm still working through this and am getting this Warning...

count(): Parameter must be an array or an object that implements Countable

here are the 2 lines of code it referring to...

Code:

$smarty->assign('pidCount'count(): Parameter must be an array or an object that implements Countable, count(isset($sale['criteria']['purchase_products']) ? $sale['criteria']['purchase_products'] : 0)+count(isset($sale['criteria']['received_products']) ? $sale['criteria']['received_products'] : 0)+1);
        $smarty->assign('wPidCount', count(isset($sale['criteria']['wholesale']) ? $sale['criteria']['wholesale'] : 0)+1);                       


Should this be different for php7?

Thomasb134 07-05-2019 10:46 AM

Re: altered carts OnSale mod for php 7+
 
That warning was suppressed in earlier PHP versions. But now PHP7.2+ has elevated the warning to encourage better coding practices.

The solution is to test the variable to confirm it is countable BEFORE counting it. It would be something like this:
Code:

$smarty->assign('wPidCount', (($sale['criteria']['wholesale'] instanceof Countable) && count(isset($sale['criteria']['wholesale'])) ? $sale['criteria']['wholesale'] : 0)+1);

This is just a coding example and may not work as-is. My example is just to give you a fundamental idea on how to fix it.

BTW, PHP7.3 introduced the is_countable() function as alternate way to do the "instanceof Countable" var test. Details here:
https://www.php.net/manual/en/function.is-countable.php

.

keystone 07-30-2019 01:04 PM

Re: altered carts OnSale mod for php 7+
 
I've worked through the changes that were suggested and still don't have this working right. I get a bunch of Undefined index: and Undefined variable: notices and have no idea how to fix them. For example...

Undefined index
Quote:

Notice: Undefined index: use_taxed_price_product in /home/keyston1/public_html.dev/modules/alteredCart_On_Sale/onsale_sessions.php on line 23
Notice: Undefined index: no_globals_w_ind in /home/keyston1/public_html.dev/modules/alteredCart_On_Sale/onsale_sessions.php on line 39



Code:

// Load Settings //
x_session_register('onsale_settings');
$GLOBALS['onsale_settings'] = unserialize(func_query_first_cell("SELECT settings FROM xcart_onsale_settings WHERE os_set_id='1'"));

// Taxed Price //
$GLOBALS['onsale_settings']['use_taxed_price'] = $GLOBALS['onsale_settings']['use_taxed_price_product'] == 'Y' ? 'Y' : ''; // LINE 23
$smarty->assign('onsale_settings', $GLOBALS['onsale_settings']);

x_session_register('_message');
x_session_register('added_sales');
x_session_register('onsale_shipping');
x_session_register('cart');

$smarty->assign('onsale_messages', $_message);

// Get the Coupon Code //
$coupon_code = '';       

// Array of saletypes with discounts that load on the product/catalog page //
$cp_display = array('5', '10');

if ($GLOBALS['onsale_settings']['no_globals_w_ind'] == 'Y'){    // LINE 39
        $ind_pids = onsale_load_ind_productids();
}


example of Undefinded variable
Quote:

Undefined variable: p_query in /home/keyston1/public_html.dev/modules/alteredCart_On_Sale/onsale_functions.php on line 524


Code:

        $query = "SELECT * FROM $sql_tbl[onsale]
                        WHERE begin < '".$__time."'
                        AND end > '".$__time."'
                        AND status IN ('A', 'S', 'E') $p_query $c_query $ospage_filter    // LINE 524
                        ORDER BY order_to_apply ASC";
                       
        $md5 = md5($query);
       


can someone give me an example of what I should do so I can fix the rest of them? I tried google but they talk way over my head so it's like comparing apples to oranges.
Thanks.

cflsystems 07-30-2019 04:22 PM

Re: altered carts OnSale mod for php 7+
 
These are notices not even warnings. So you can ignore them. If you want them to go away you will have to assign a value no matter what.

So for example for the $p_query you need to find where its value is assigned somewhere before this line 524 and check if value is not assign and you can do something like

$p_query = '';

It will highly depend on the code there what it does and how it does it to decide how to assign the variable value.

keystone 07-31-2019 05:06 AM

Re: altered carts OnSale mod for php 7+
 
So what you are saying is that those notices are not the cause of why the mod isn't working. I don't care about the notices being there but I thought those might have been the problem since they are the only "errors" showing up in my logs.

cflsystems 07-31-2019 05:21 AM

Re: altered carts OnSale mod for php 7+
 
I'm saying the notices will not prevent the cart or module from working yes. However these variables not having a value may be the reason for the module not to work properly or maybe it is working properly just not doing what you expect it to do.
Another reason is when and how the module is making changes and adding whatever it supposed to add to the cart. If the code base is different it is possible the module's files need change as well...

Notice: Undefined index: no_globals_w_ind in /home/keyston1/public_html.dev/modules/alteredCart_On_Sale/onsale_sessions.php on line 39

no_globals_w_ind not being defined at all means this code will never run

Code:

if ($GLOBALS['onsale_settings']['no_globals_w_ind'] == 'Y'){    // LINE 39
        $ind_pids = onsale_load_ind_productids();
}


So you need to find where no_globals_w_ind get's set and when it is set to Y or something else and how this affects the rest of the module logic.

keystone 07-31-2019 11:14 AM

Re: altered carts OnSale mod for php 7+
 
Thanks for the clarification Steve. Just out of curiosity, did you go to school to learn coding or are you self taught?

cflsystems 07-31-2019 01:43 PM

Re: altered carts OnSale mod for php 7+
 
Quote:

Originally Posted by keystone
Thanks for the clarification Steve. Just out of curiosity, did you go to school to learn coding or are you self taught?



Self-taught

keystone 08-13-2019 01:39 PM

Re: altered carts OnSale mod for php 7+
 
I have revisited X-Carts Special Offers built in mod because I saw that they actually DO have the ability to restrict a special offer to a specific membership group. I do have a question regarding that specific condition however. The Mod states
Quote:

If no memberships are selected, only the customers with no membership will match the condition.

So when I leave the membership area with no selected options and put a check in the checkbox next to
Quote:

Customer has a certain membership
I should be able to log in as a member and the Special Offer should not be applied but it still does. When I go back to the Special Offer in admin and check the conditions, the checkbox is no longer checked. It doesn't seem to like that there is no membership selected even though it says that is the only way to make the sale not show up for customers who have a membership level.

Anyone have this issue or does it work correctly for others? Is there a way to add "No Membership or Not Logged In" as an option to select? Thanks for any ideas... This is for x-cart version 4.7.11, just realized I didn't update my signature yet.

elmirage001 08-14-2019 10:39 AM

Re: altered carts OnSale mod for php 7+
 
After updating the membership option keep proceeding through the Special Bonus process until you can click on the Finish Button. After clicking the Finish Button go back in and see if it keeps your membership choice including none of them highlighted.

I first selected a membership clicked update and went through the process until I clicked Finish. I went back in and it held the membership choice. I then deselected that membership choice so that none were highlighted and clicked update and proceeded until I could click the Finish Button. When I went back into the Special Offer the Customer has a certain membership checkbox was checked and none of the memberships were highlighted. I don't use Special Offers so I did not do any further testing.

keystone 08-14-2019 11:11 AM

Re: altered carts OnSale mod for php 7+
 
Hey elmirage, When I did what you suggested it kept the check in the box. I'll have to do some further testing but it seems like it does work, not sure exactly which step determines if the check stays in or comes out yet. Thanks for the help.

keystone 08-16-2019 01:30 PM

Re: altered carts OnSale mod for php 7+
 
When a special offer is applied to a product, the "Special Offer" icon shows on the product image on the product pages, category pages, and in the shopping cart. When I restrict the Special Offer to only customers with NO membership, then I log in as a test wholesale member, the special offer icon is removed from the category and product page images BUT, if I add the product to the shopping cart, the ICON shows back up on the product image in the cart...
I think that the code was just missed to restrict the icon on the cart page as well as the category and product pages. Does anyone know where/how to add that?

I can foresee a bunch of email/phone calls from my wholesale accounts asking about the special offer (that isn't valid for them).
Thanks.

elmirage001 08-19-2019 03:22 PM

Re: altered carts OnSale mod for php 7+
 
It's working correctly for me.

Sign in on account with no membership --> Cart shows special offers message and promotion price.

Sign in on account with membership = Wholesale --> Cart does not show message and the price is correct, not discounted.

Change wholesale account to Not Member --> Cart shows special offers message and promotion price.

keystone 08-20-2019 04:58 AM

Re: altered carts OnSale mod for php 7+
 
Yeah, the pricing is correct when I switch back and forth between member and not member but the "Special Offer" badge/star on the image in the cart still shows up when I switch to membership = wholesale. Does yours go away? BTW I'm using the x-carts One Page Checkout.

elmirage001 08-20-2019 01:23 PM

Re: altered carts OnSale mod for php 7+
 
I don't see the badge at all on 4.7.11 on reBOOT, Light Responsive, or Ideal Responsive templates.

Can you upload a image of it?

What XC version?

Template?

Thanks!

keystone 08-21-2019 01:37 PM

Re: altered carts OnSale mod for php 7+
 
1 Attachment(s)
I am using Ideal Responsive template xc version 4.7.11 GoldPlus. Here is an image if my cart as a wholesale member and the badge is still there.

elmirage001 08-21-2019 03:20 PM

Re: altered carts OnSale mod for php 7+
 
Thanks for that. It helped a lot!

The badge would not show up with the Special Offer Discount I created. I had to go to your site and see exactly what your Special Offer was. Once I set up the BOGO for a product on my dev site the same as you did the Special Offer Badge showed up.

In skin/ideal_responsive/customer/main/cart.tpl

Around Line # 48 - Comment out the following code.

Code:

{if $active_modules.Special_Offers ne "" and $product.have_offers}
    {include file="modules/Special_Offers/customer/product_offer_thumb.tpl"}
{/if}

This removed the badge from my dev site and hopefully works for you.

keystone 08-22-2019 10:38 AM

Re: altered carts OnSale mod for php 7+
 
could I do something like this so the badge shows up for NON members but is hidden when a customer has a membership or will that not work? (not sure if my additional code is correct)

Code:

{if $active_modules.Special_Offers ne "" and $product.have_offers and $_userinfo.membership eq ""}
{include file="modules/Special_Offers/customer/product_offer_thumb.tpl"}
{/if}

I does remove it completely when I comment out the line like you said but I thought it would be nice to show to customers it is meant for and hide it from everyone else.

elmirage001 08-22-2019 12:46 PM

Re: altered carts OnSale mod for php 7+
 
Try this
Code:

{if $active_modules.Special_Offers ne "" and $product.have_offers and $userinfo.membership ne "Wholesale"}

keystone 08-23-2019 11:04 AM

Re: altered carts OnSale mod for php 7+
 
ah, perfect, it works. I had used
Code:

$_userinfo.membership
instead of
Code:

$userinfo.membership
because in the order invoice template /ideal_responsive/mail/html/order_invoice.tpl they use that as the variable. I didn't think to check the variable for the cart page as I thought it would have been the same.
Thanks.

elmirage001 08-23-2019 11:34 AM

Re: altered carts OnSale mod for php 7+
 
Glad it's working for you!

Paul

zone1creative 09-09-2019 12:20 AM

Re: altered carts OnSale mod for php 7+
 
Can I just say the altered cart onsale module for xcart 4 is awesome. Even though it is no longer maintained it is essential for every new store I build.

This sort of functionality should be core in xcart. It makes the difference when comparing shopping carts.


All times are GMT -8. The time now is 09:42 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.