Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions inc/ajax-fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
<?php
$db = $pdo->query("SELECT p.* FROM products as p JOIN categories as c on p.id_cat = c.id and c.lang = '".$_SESSION["l"]."' where p.title LIKE '%".$_POST["fetch"]."%' and p.active = 1 order by p.ord ASC");
while ($row = $db->fetch()) {
// we get the TAX for that product
$rowt["tax"] = 0; // we set default to zero
if (isset($_SESSION["country"])){ // we check if Shibe is logged in and we get only shipping from all countries or his own country
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' and country = '".$_SESSION["country"]."' limit 1")->fetch();
// we get the TAX for that product (safe if tax table missing)
if (isset($_SESSION["country"])){
$rowt = $d->GetTaxRow($row["cat_tax"], $_SESSION["country"]);
}else{
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' limit 1")->fetch();
$rowt = $d->GetTaxRow($row["cat_tax"]);
}

?>
Expand Down
21 changes: 21 additions & 0 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,27 @@ public function RemoveShipping($id)


//// tax /////////
// Safe tax lookup — returns ['tax' => 0] when table/row is missing (fresh installs).
public function GetTaxRow($category, $country = null)
{
$default = array("tax" => 0);
$category = filter_var((string)$category, FILTER_SANITIZE_ADD_SLASHES);
try {
if ($country !== null && $country !== '') {
$country = filter_var((string)$country, FILTER_SANITIZE_ADD_SLASHES);
$row = $this->pdo->query("SELECT * FROM tax WHERE category = '".$category."' AND country = '".$country."' LIMIT 1")->fetch();
} else {
$row = $this->pdo->query("SELECT * FROM tax WHERE category = '".$category."' LIMIT 1")->fetch();
}
if ($row && isset($row["tax"])) {
return $row;
}
} catch (Throwable $e) {
// Missing tax table or column — treat as zero rate so listings stay up.
}
return $default;
}

// Add tax
public function InsertTax($category,$country,$tax,$active)
{
Expand Down
50 changes: 27 additions & 23 deletions inc/listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,34 +150,38 @@ function formatText (icon) {
<input type="number" step="any" name="fiat" class="form-control" min="0" value="<?php if (isset($row["fiat"])){ echo $row["fiat"]; }; ?>" placeholder="0">
</div>
</div>
<!-- <div class="col-sm-4" >
<?php
// Tax category dropdown. HTML comments do NOT stop PHP execution — this used to
// fatal on fresh installs when the `tax` table was missing from shibeship.sql.
$taxCategories = array();
try {
$dbsub = $pdo->query("SELECT DISTINCT category FROM tax ORDER BY category ASC");
if ($dbsub) {
while ($rowsub = $dbsub->fetch()) {
if (isset($rowsub["category"])) {
$taxCategories[] = $rowsub["category"];
}
}
}
} catch (Throwable $e) {
$taxCategories = array();
}
?>
<div class="col-sm-4">
<div class="form-group">
<label><?php echo $lang["tax"]; ?> %</label>
<select class="form-control" name="cat_tax">
<?php
$dbsub = $pdo->query("SELECT DISTINCT category FROM tax order by category ASC");
while ($rowsub = $dbsub->fetch()) {
?>
<option value="<?php echo $rowsub["category"];?>" ><?php echo $rowsub["category"];?></option>
<?php
};
?>
<?php
if (isset($row["cat_tax"])){
?>
<option value="<?php echo $row["cat_tax"];?>" selected="selected" ><?php echo $row["cat_tax"];?></option>
<?php
}else{
?>
<option value="" selected="selected" >---</option>
<?php
}
?>
<option value="" >0</option>
<option value="0"<?php if (!isset($row["cat_tax"]) || $row["cat_tax"] === "" || $row["cat_tax"] === "0"){ echo ' selected="selected"'; } ?>>0</option>
<?php foreach ($taxCategories as $taxCat) { if ($taxCat === "0" || $taxCat === "") continue; ?>
<option value="<?php echo htmlspecialchars($taxCat, ENT_QUOTES); ?>"<?php if (isset($row["cat_tax"]) && $row["cat_tax"] === $taxCat){ echo ' selected="selected"'; } ?>><?php echo htmlspecialchars($taxCat, ENT_QUOTES); ?></option>
<?php } ?>
<?php if (isset($row["cat_tax"]) && $row["cat_tax"] !== "" && $row["cat_tax"] !== "0" && !in_array($row["cat_tax"], $taxCategories, true)) { ?>
<option value="<?php echo htmlspecialchars($row["cat_tax"], ENT_QUOTES); ?>" selected="selected"><?php echo htmlspecialchars($row["cat_tax"], ENT_QUOTES); ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
-->

<div class="col-sm-4">
<div class="form-group">
<label><?php echo $lang["qty"]; ?></label>
Expand Down
9 changes: 4 additions & 5 deletions inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
<?php
$db = $pdo->query("SELECT p.* FROM products as p JOIN categories as c on p.id_cat = c.id and c.lang = '".$_SESSION["l"]."' where p.active = 1 order by p.id DESC");
while ($row = $db->fetch()) {
// we get the TAX for that product
$rowt["tax"] = 0; // we set default to zero
if (isset($_SESSION["country"])){ // we check if Shibe is logged in and we get only shipping from all countries or his own country
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' and country = '".$_SESSION["country"]."' limit 1")->fetch();
// we get the TAX for that product (safe if tax table missing)
if (isset($_SESSION["country"])){
$rowt = $d->GetTaxRow($row["cat_tax"], $_SESSION["country"]);
}else{
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' limit 1")->fetch();
$rowt = $d->GetTaxRow($row["cat_tax"]);
}
?>
<?php include("product_main.php"); //we include the product design ?>
Expand Down
20 changes: 11 additions & 9 deletions inc/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ function randomDogeemonic(min, max) {
};
$rowc = $pdo->query("SELECT * FROM categories where id = '".$row["id_cat"]."' limit 1")->fetch();
$shibe = $pdo->query("SELECT * FROM shibes where id = '".$row["id_shibe"]."' limit 1")->fetch();
// we get the TAX for that product
$rowt["tax"] = 0; // we set default to zero
if (isset($_SESSION["country"])){ // we check if Shibe is logged in and we get only shipping from all countries or his own country
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' and country = '".$_SESSION["country"]."' limit 1")->fetch();
}else{
// we get the TAX for that product (safe if tax table missing)
if (isset($_SESSION["country"])){
$rowt = $d->GetTaxRow($row["cat_tax"], $_SESSION["country"]);
}else{
$rowt = $d->GetTaxRow($row["cat_tax"]);
}else{
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' limit 1")->fetch();
}

Expand Down Expand Up @@ -441,10 +442,11 @@ function randomDogeemonic(min, max) {
<?php // we list all products
$db = $pdo->query("SELECT p.* FROM products as p JOIN categories as c on p.id_cat = c.id and c.lang = '".$_SESSION["l"]."' where p.id_cat = '".$row["id_cat"]."' and p.id <> '".$_GET["product"]."' and p.active = 1 order by p.ord ASC");
while ($row = $db->fetch()) {
// we get the TAX for that product
$rowt["tax"] = 0; // we set default to zero
if (isset($_SESSION["country"])){ // we check if Shibe is logged in and we get only shipping from all countries or his own country
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' and country = '".$_SESSION["country"]."' limit 1")->fetch();
// we get the TAX for that product (safe if tax table missing)
if (isset($_SESSION["country"])){
$rowt = $d->GetTaxRow($row["cat_tax"], $_SESSION["country"]);
}else{
$rowt = $d->GetTaxRow($row["cat_tax"]);
}else{
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' limit 1")->fetch();
}
Expand Down
9 changes: 4 additions & 5 deletions inc/products.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
<?php // we list all products
$db = $pdo->query("SELECT p.* FROM products as p JOIN categories as c on p.id_cat = c.id and c.lang = '".$_SESSION["l"]."' where p.id_cat = '".$_GET["c"]."' and p.active = 1 order by p.ord ASC");
while ($row = $db->fetch()) {
// we get the TAX for that product
$rowt["tax"] = 0; // we set default to zero
if (isset($_SESSION["country"])){ // we check if Shibe is logged in and we get only shipping from all countries or his own country
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' and country = '".$_SESSION["country"]."' limit 1")->fetch();
// we get the TAX for that product (safe if tax table missing)
if (isset($_SESSION["country"])){
$rowt = $d->GetTaxRow($row["cat_tax"], $_SESSION["country"]);
}else{
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' limit 1")->fetch();
$rowt = $d->GetTaxRow($row["cat_tax"]);
}
?>
<?php include("product_main.php"); //we include the product design ?>
Expand Down
9 changes: 4 additions & 5 deletions inc/shop.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@
<?php // we list all products
$db = $pdo->query("SELECT p.* FROM products as p JOIN categories as c on p.id_cat = c.id and c.lang = '".$_SESSION["l"]."' where p.id_shibe = '".$_GET["shibe"]."' and p.active = 1 order by p.ord ASC");
while ($row = $db->fetch()) {
// we get the TAX for that product
$rowt["tax"] = 0; // we set default to zero
if (isset($_SESSION["country"])){ // we check if Shibe is logged in and we get only shipping from all countries or his own country
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' and country = '".$_SESSION["country"]."' limit 1")->fetch();
// we get the TAX for that product (safe if tax table missing)
if (isset($_SESSION["country"])){
$rowt = $d->GetTaxRow($row["cat_tax"], $_SESSION["country"]);
}else{
$rowt = $pdo->query("SELECT * FROM tax where category = '".$row["cat_tax"]."' limit 1")->fetch();
$rowt = $d->GetTaxRow($row["cat_tax"]);
}
?>
<?php include("product_main.php"); //we include the product design ?>
Expand Down
21 changes: 20 additions & 1 deletion shibeship.sql
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,23 @@ CREATE TABLE `shibes` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


-- 2023-07-13 17:16:04

DROP TABLE IF EXISTS `tax`;
CREATE TABLE `tax` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`category` varchar(255) NOT NULL DEFAULT '',
`country` varchar(255) DEFAULT NULL,
`tax` decimal(10,4) NOT NULL DEFAULT '0.0000',
`active` int(1) DEFAULT '1',
PRIMARY KEY (`id`),
KEY `idx_tax_category` (`category`),
KEY `idx_tax_country` (`country`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- Default zero-rate row so listings tax dropdown is never empty after fresh install
INSERT INTO `tax` (`id`, `category`, `country`, `tax`, `active`) VALUES
(1,'0',NULL,0.0000,1),
(2,'Standard','',0.0000,1);


-- 2023-07-13 17:16:04