X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Price Update/Import by membership level mode (https://forum.x-cart.com/showthread.php?t=4315)

finestshops 09-11-2003 09:14 AM

Price Update/Import by membership level mode
 
Here is a simple mode for product price update by membership level.
This mod will update or add product/price/membership data from csv file.

/provider/price_update.php

Note:
$columns[0] - is your product code in import file
$columns[1] - is your product price in import file

Code:

<?
/*****************************************************************************\
+-----------------------------------------------------------------------------+
| X-Cart                                                                      |
| Copyright (c) 2001-2003 Ruslan R. Fazliev <rrf@rrf.ru>                      |
| All rights reserved.                                                        |
+-----------------------------------------------------------------------------+
| PLEASE READ  THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" |
| FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE  |
| AT THE FOLLOWING URL: http://www.x-cart.com/license.php                    |
|                                                                            |
| THIS  AGREEMENT  EXPRESSES  THE  TERMS  AND CONDITIONS ON WHICH YOU MAY USE |
| THIS SOFTWARE  PROGRAM  AND  ASSOCIATED  DOCUMENTATION  THAT  RUSLAN  R. |
| FAZLIEV (hereinafter  referred to as "THE AUTHOR") IS FURNISHING  OR MAKING |
| AVAILABLE TO YOU WITH  THIS  AGREEMENT  (COLLECTIVELY,  THE  "SOFTWARE").  |
| PLEASE  REVIEW  THE  TERMS  AND  CONDITIONS  OF  THIS  LICENSE AGREEMENT |
| CAREFULLY  BEFORE  INSTALLING  OR  USING  THE  SOFTWARE.  BY INSTALLING, |
| COPYING  OR  OTHERWISE  USING  THE  SOFTWARE,  YOU  AND  YOUR  COMPANY |
| (COLLECTIVELY,  "YOU")  ARE  ACCEPTING  AND AGREEING  TO  THE TERMS OF THIS |
| LICENSE  AGREEMENT.  IF  YOU    ARE  NOT  WILLING  TO  BE  BOUND BY THIS |
| AGREEMENT, DO  NOT INSTALL OR USE THE SOFTWARE.  VARIOUS  COPYRIGHTS  AND |
| OTHER  INTELLECTUAL  PROPERTY  RIGHTS    PROTECT  THE  SOFTWARE.  THIS |
| AGREEMENT IS A LICENSE AGREEMENT THAT GIVES  YOU  LIMITED  RIGHTS  TO  USE |
| THE  SOFTWARE  AND  NOT  AN  AGREEMENT  FOR SALE OR FOR  TRANSFER OF TITLE.|
| THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT.      |
|                                                                            |
| The Initial Developer of the Original Code is Ruslan R. Fazliev            |
| Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2003          |
| Ruslan R. Fazliev. All Rights Reserved.                                    |
+-----------------------------------------------------------------------------+
\*****************************************************************************/

#
# $Id: price_update.php,v 1 2003/09/10 ant Exp $
#

@set_time_limit(1800);

require "../smarty.php";
require "../config.php";
require "./auth.php";
require "../include/security.php";

if ($REQUEST_METHOD=="POST") {

        $provider_condition=($single_mode?"":" AND $sql_tbl[products].provider='$login'");
       
        if($fp = @fopen($userfile,"r")) {
                while ($columns = fgetcsv ($fp, 65536, $delimiter)) {
                        if ($columns[0]) {
                                if ($what == "p") {
                                        $pid = func_query_first ("SELECT * FROM $sql_tbl[products] WHERE productcode='$columns[0]' $provider_condition");

                                        $f = "SELECT count(*) FROM $sql_tbl[pricing] WHERE productid='$pid[productid]' AND membership='$membership' AND quantity=1";
                                        echo $f."
";
                                        $tmp = array_pop(func_query_first($f));
                                        # $tmp = db_query ($f);
                                        echo $tmp."
";
                               
                                        if ($tmp != 0)
                                        {
                                        $f = "UPDATE $sql_tbl[pricing] SET price='$columns[1]' WHERE productid='$pid[productid]' AND membership='$membership' AND quantity=1";
                                        echo $f."
";
                                        db_query ($f);
                                        }
                                        else
                                        {
                                        $f = "INSERT $sql_tbl[pricing] VALUES ('','$pid[productid]','1','$columns[1]','$membership')";
                                        echo $f."
";
                                        db_query ($f);
                                        }
                                }
                        }
                }
                $smarty->assign("main", "price_updated");
        } else {
                $smarty->assign("main", "error_inv_update");
        }
} else {
        $smarty->assign ("main", "price_update");
}

require "../include/categories.php";

@include "../modules/gold_display.php";
$smarty->display("provider/home.tpl");
?>


skin1/single/home.tpl

Code:


After:

{elseif $main eq "inv_update"}
{include file="provider/main/inv_update.tpl"}

Add:

{elseif $main eq "price_update"}
{include file="provider/main/price_update.tpl"}


skin1/provider/main/price_update.tpl

Code:

{* $Id: price_update.tpl,v 1.0 2003/09/10 ant Exp $ *}
{include file="location.tpl" last_location="Price update"}
{capture name=dialog}


<h3><font color=red>Script is in testing! Please back up database!</font></h3>


<FORM method=POST action="price_update.php" enctype="multipart/form-data">
<TABLE border=0 cellpadding=0 cellspacing=4 width="100%">

<TR>
<TD>Membership</TD>
<TD>
<select name=membership>
<option value="">Default Price</option>
{section name=level loop=$membership_levels}
<option value="{$membership_levels[level].membership}">{$membership_levels[level].membership}</option>
{/section}
</select>

</TD>
</TR>
<TR>
<TD>Update</TD>
<TD><SELECT name=what>
 <OPTION value="p" selected>Pricing</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD>CSV delimiter</TD>
<TD>{include file="provider/main/ie_delimiter.tpl"}</TD>
</TR>
<TR>
<TD>CSV file</TD>
<TD><INPUT type=file name=userfile></TD>
</TR>
<TR>
<TD colspan=2><INPUT type=submit value="Update">
</TABLE>
</FORM>
{/capture}
{include file="dialog.tpl" content=$smarty.capture.dialog title="Price Update" extra="width=100%"}


skin1/provider/menu.tpl

Code:


After:

Update inventory


Add:

Price Update



Let me know if I missed something.

dealsondeals 09-27-2003 03:09 PM

What version is this mod for?

Thanks,

Glen

finestshops 09-27-2003 05:38 PM

Quote:

Originally Posted by dealsondeals
What version is this mod for?


I used it in 3.4.4 and 3.4.7
should work in any 3.4.*

dealsondeals 09-27-2003 06:56 PM

:D Thanks Anton!

I'll implement it, just did a install of 3.4.7 and looking to see what bells and whistles to add.

Regards,

Glen

adpboss 11-15-2003 04:25 PM

This is nice but I wish I was smart enough to figure out how to import pricing by qty (wholesale pricing). If it could create and import quantity pricing it would truly be the bomb.

Nice mod nonetheless, thanks Anton.

finestshops 11-15-2003 04:39 PM

Quote:

Originally Posted by adpboss
If it could create and import quantity pricing it would truly be the bomb.


This is easy. I'm using it already for several months.
Modify import file like this:

$columns[0] - is your product code in import file
$columns[1] - is your product price in import file
$columns[2] - is your product min qty for this price price in import file

in 2 places change

Code:

quantity=1

to

Code:

quantity='$columns[2]'

change

Code:

$f = "INSERT $sql_tbl[pricing] VALUES ('','$pid[productid]','1','$columns[1]','$membership')";

to

Code:

$f = "INSERT $sql_tbl[pricing] VALUES ('','$pid[productid]','$columns[2]','$columns[1]','$membership')";


done
enjoy

adpboss 11-15-2003 04:43 PM

Anton, you are simply the greatest.

I was about to go back and do another mod that is similar but doesnt add to the pricing tables.

For reference that mod is located here
http://forum.x-cart.com/viewtopic.php?t=1696

The only question I still have about this mod is what happens when someone accidentally has the same sku for 2 products? Wouldn't that pooch the whole thing?

I prefer to update off of Product ID if possible.

finestshops 11-15-2003 04:53 PM

Quote:

Originally Posted by adpboss
The only question I still have about this mod is what happens when someone accidentally has the same sku for 2 products? Wouldn't that pooch the whole thing?
I prefer to update off of Product ID if possible.


With product id this would be much easier, but most people do not know have product id, they only have productcode.

If you want ptoduct id, just change

$pid[productid]

to

$columns[0]

adpboss 11-15-2003 04:54 PM

This is wonderful, thank you so much for supporting this mod with me.

I really do appreciate it.

finestshops 11-15-2003 05:04 PM

Let me know if it works :lol:


All times are GMT -8. The time now is 12:58 PM.

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