Only follow this if you feel like manually editing alot of code and also editing your database by hand.. I don't feel like actually making adding shops nice and easy.
.
Also
BACK UP ALL FILES BEFORE YOU START! incase I messed up.
. Also when I sya "line 201" that means 201 of the unedited file. If you have made other changes, including the ones you make while editing the file, these line numbers may change. Sorry about that.
Your first task it to edit the Shop-Buy.php file.
After line 24 add
if (!isset($_GET['store'])) {
die("Please select a store!");
}
if ($_GET['store'] < 1 || $_GET['store'] > 5) {
die("Please select a valid store");
}
At line 117 find this part of the code:
$result = db_query("SELECT name, `desc`, price, stock, id, image, shop
FROM {$db_prefix}shop_items
ORDER BY {$sortQuery} {$sortDirQuery}", __FILE__, __LINE__);
and replace it with
$result = db_query("SELECT name, `desc`, price, stock, id, image
FROM {$db_prefix}shop_items
WHERE shopid = {$_GET['store']}
ORDER BY {$sortQuery} {$sortDirQuery}",
__FILE__, __LINE__);
Next, line 149
$context['shop_items_list'] .= "<a href='$scripturl?action=shop;do=buy2;id={$itemRows[$x]['id']}'>{$txt['shop_buynow']}</a>";
Make that
$context['shop_items_list'] .= "<a href='$scripturl?action=shop;do=buy2;store={$_GET['store']};id={$itemRows[$x]['id']};'>{$txt['shop_buynow']}</a>";
Line 169:
$context['shop_page_link'] = $scripturl."?action=shop;do=buy;sort=".$_GET['sort'].";sortDir=".$_GET['sortDir'];
replace it with
$context['shop_page_link'] = $scripturl."?action=shop;do=buy;store=".$_GET['store'].";sort=".$_GET['sort'].";sortDir=".$_GET['sortDir'];
after line 177 add:
if (!isset($_GET['store'])) {
die("Please select a store!");
}
if ($_GET['store'] < 1 || $_GET['store'] > 5) {
die("Please select a valid store");
}
Line 190. Find
$result = db_query("SELECT price, stock, name
FROM {$db_prefix}shop_items
WHERE id = {$_GET['id']}
LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
replace it with
$result = db_query("SELECT price, stock, name, shopid
FROM {$db_prefix}shop_items
WHERE id = {$_GET['id']}
LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if ($row['shopid'] != $_GET['store']) {
die ("That item cannot be purchased in this store");
}
And yay! That file is done!
While you are at it; lets make our shops restock themselves as well. No more annoying by hand stuff.
add this after line 42.
$time = date("zH");
$result = db_query("UPDATE {$db_prefix}shop_items
SET stock = stock + restock
WHERE laststock <= $time - timer AND stock <= maxrestock", __FILE__, __LINE__);
$result = db_query("UPDATE {$db_prefix}shop_items
SET laststock = $time
WHERE laststock <= $time - timer", __FILE__, __LINE__);
$times = date("z");
if ($modSettings['rateday'] != $times) {
$newrate = mt_rand(100,300);
$newrate= $newrate / 100;
$result = db_query("UPDATE {$db_prefix}settings
SET value = {$newrate}
WHERE variable = 'rate'", __FILE__, __LINE__);
$result = db_query("UPDATE {$db_prefix}settings
SET value = {$times}
WHERE variable = 'rateday'", __FILE__, __LINE__);
}
Ok. So those two files are done! Time to play with the templetes!
Line 29 of Shop.templete.php
<a href="$scripturl?action=shop;do=buy">{$txt['shop_buy']}</a><br />
replace that with
<a href="$scripturl?action=shop;do=buy;store=1">[i]Store 1 desp.[/i]</a><br />
<a href="$scripturl?action=shop;do=buy;store=2">[i]Store 2 desp.[/i]</a><br />
<a href="$scripturl?action=shop;do=buy;store=3">[i]Store 3 desp.[/i]</a><br />
.
.
.
<a href="$scripturl?action=shop;do=buy;store=n">[i]Store n desp.[/i]</a><br />
Where n is the number of stores. Rename "store 1 desp" whatever you want to call that store.
Ok. Now we get to play with the admin part of the store!
in shopAdmin.templete.php instert after line 179
Amount to stock per restock: <input name="restock" type="text" value="{$context['shop_items_item']['restock']}" size="5"<br />
Time between restocks: <input name="timer" type="text" value="{$context['shop_items_item']['timer']}" size="5"<br />
Max amount to stock: <input name="maxstock" type="text" value="{$context['shop_items_item']['maxstock']}" size="5"<br />
ID of shop to stock in: <input name="shopid" type="text" value="{$context['shop_items_item']['shopid']}" size="5"<br />
and then do the SAME THING after line 220.
Ok, last file. ShopAdmin.php
line 201. Instert this after it
'restock' => 1,
'timer' => 6,
'maxstock' => 10,
'shopid' => 1
line 225. Fine and replace
$sql = "INSERT
INTO {$db_prefix}shop_items
(name, `desc`, price, module, stock, input_needed, can_use_item, info1, info2, info3, info4, image)
VALUES (
'{$_POST['itemname']}',
'{$_POST['itemdesc']}',
{$_POST['itemprice']},
'{$_POST['item']}',
{$_POST['itemstock']},
{$_POST['require_input']},
{$_POST['can_use_item']},
'{$_POST['info1']}',
'{$_POST['info2']}',
'{$_POST['info3']}',
'{$_POST['info4']}',
'{$_POST['icon']}'
)";
replace with
$sql = "INSERT
INTO {$db_prefix}shop_items
(name, `desc`, price, module, stock, input_needed, can_use_item, info1, info2, info3, info4, image, restock, timer, maxrestock, shopid)
VALUES (
'{$_POST['itemname']}',
'{$_POST['itemdesc']}',
{$_POST['itemprice']},
'{$_POST['item']}',
{$_POST['itemstock']},
{$_POST['require_input']},
{$_POST['can_use_item']},
'{$_POST['info1']}',
'{$_POST['info2']}',
'{$_POST['info3']}',
'{$_POST['info4']}',
'{$_POST['icon']}',
'{$_POST['restock']}',
'{$_POST['timer']}',
'{$_POST['maxstock']}',
'{$_POST['shopid']}'
)";
line 262. Find and replace
$result = db_query("SELECT name, `desc`, price, stock, image
FROM {$db_prefix}shop_items
WHERE id = {$_GET['id']}"
, __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$context['shop_edit'] = array(
'id' => $_GET['id'],
'name' => $row['name'],
'desc' => $row['desc'],
'price' => $row['price'],
'stock' => $row['stock'],
'image' => $row['image'],
);
} elseif ($_GET['do'] == "edit2") {
$context['shop_items_edit'] = 2;
$result = db_query("UPDATE {$db_prefix}shop_items
SET name = '{$_POST['itemname']}',
`desc` = '{$_POST['itemdesc']}',
price = {$_POST['itemprice']},
stock = {$_POST['itemstock']},
image = '{$_POST['icon']}'
WHERE id = {$_POST['id']}
LIMIT 1"
, __FILE__, __LINE__);
with
$result = db_query("SELECT name, `desc`, price, stock, image, restock, timer, maxrestock, shopid
FROM {$db_prefix}shop_items
WHERE id = {$_GET['id']}"
, __FILE__, __LINE__);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$context['shop_edit'] = array(
'id' => $_GET['id'],
'name' => $row['name'],
'desc' => $row['desc'],
'price' => $row['price'],
'stock' => $row['stock'],
'image' => $row['image'],
'restock' => $row['restock'],
'timer' => $row['timer'],
'maxstock' => $row['maxrestock'],
'shopid' => $row['shopid']
);
} elseif ($_GET['do'] == "edit2") {
$context['shop_items_edit'] = 2;
$result = db_query("UPDATE {$db_prefix}shop_items
SET name = '{$_POST['itemname']}',
`desc` = '{$_POST['itemdesc']}',
price = {$_POST['itemprice']},
stock = {$_POST['itemstock']},
image = '{$_POST['icon']}',
restock = {$_POST['restock']},
timer = {$_POST['timer']},
maxrestock = {$_POST['maxstock']},
shopid = {$_POST['shopid']}
WHERE id = {$_POST['id']}
LIMIT 1", __FILE__, __LINE__);
And there you go. You have a shop.
But wait, there is still the database to edit! Silly us
Anyways, you need to add these four cols to the shop_shop_items database:
Field Type Attributes Null Default
timer int(10) UNSIGNED No 6
laststock int(10) UNSIGNED No 0
used int(10) UNSIGNED No 0
maxrestock int(10) UNSIGNED No 15
And after you do that, upload everything, cross your fingers, and hope it works. It probably won't, but you can post whatever error you get here and I can try to help you fix it.