View Single Post
  #1  
Old 09-14-2003, 08:18 AM
  finestshops's Avatar 
finestshops finestshops is offline
 

eXpert
  
Join Date: Oct 2002
Location: Toronto, Canada
Posts: 335
 

Default Import product options

Here is my mod for batch upload of product options:

here is format of file for options import:

productcode, opttext, options

Code:
1044, Color, Black\r\nRed\r\nRoyal Blue 1044, Size, Regular\r\nXL 1068, Color, Black\r\nPeriwinkle\r\nWhite 1069, Color, Natural\r\nPurple\r\nTurquoise 1076, Color, Gold\r\nSilver 1076, Size, Regular\r\nXL 1139, Color, Black\r\nRed\r\nWhite 1139, Size, S\r\nM\r\nL 116, Color, Black\r\nWhite

create new file "xcart/provider/options_update.php"

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: options_update.php,v 1 2003/09/10 ant Exp $ # # $columns[0] - productcode # $columns[1] - opttext # $columns[2] - options @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[product_options] WHERE productid='$pid[productid]' AND optclass='$columns[1]'"; echo $f." "; $tmp = array_pop(func_query_first($f)); # $tmp = db_query ($f); # echo $tmp." "; if ($tmp != 0) { $f = "UPDATE $sql_tbl[product_options] SET optclass='$columns[1]', opttext='$columns[1]', options='$columns[2]' WHERE productid='$pid[productid]'"; echo $f." "; db_query ($f); } else { $f = "INSERT $sql_tbl[product_options] VALUES ('','$pid[productid]','$columns[1]','$columns[1]','$columns[2]','0')"; echo $f." "; db_query ($f); } } } } $smarty->assign("main", "options_updated"); } else { $smarty->assign("main", "error_inv_update"); } } else { $smarty->assign ("main", "options_update"); } require "../include/categories.php"; @include "../modules/gold_display.php"; $smarty->display("provider/home.tpl"); ?>



create new template "\skin1\provider\main\options_update.tpl

Code:
{* $Id: options_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="options_update.php" enctype="multipart/form-data"> <TABLE border=0 cellpadding=0 cellspacing=4 width="100%"> <TR> <TD>Update</TD> <TD><SELECT name=what> <OPTION value="p" selected>Options</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="Options Update" extra="width=100%"}

in template "\skin1\single\home.tpl"

after

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

add

Code:
{elseif $main eq "options_update"} {include file="provider/main/options_update.tpl"}

in "\skin1\provider\menu.tpl"
after


add


The script will check if option is exist for productcode and update it
if yes or insert it if no.

I have similar script for price update by membership.

Hope this will help somebody,
__________________
Best regards,

Anton Pachkine
finestshops.com/x-cart
Reply With Quote