2020-06-25 11:37:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This Software is the property of Data Development and is protected
|
|
|
|
* by copyright law - it is NOT Freeware.
|
|
|
|
* Any unauthorized use of this software without a valid license
|
|
|
|
* is a violation of the license agreement and will be prosecuted by
|
|
|
|
* civil and criminal law.
|
|
|
|
* http://www.shopmodule.com
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <support@shopmodule.com>
|
|
|
|
* @link http://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace D3\TaxRatesAdjustment\Models;
|
|
|
|
|
2020-06-25 15:45:12 +02:00
|
|
|
use oxRegistry;
|
|
|
|
|
2020-06-25 12:01:07 +02:00
|
|
|
require_once('genericAbstract.php');
|
2020-06-25 11:37:04 +02:00
|
|
|
|
|
|
|
abstract class articlePricesAbstract extends genericAbstract
|
|
|
|
{
|
|
|
|
public $baseQueriesDefaultTax = [
|
|
|
|
//'UPDATE oxarticles SET oxprice = (oxprice / 1.19 * 1.16) WHERE oxshopid = 'oxbaseshop' AND (oxvat IS NULL);',
|
|
|
|
// default prices
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxprice = (oxprice / ? * ?) WHERE oxshopid = ? AND (oxvat IS NULL)',
|
2020-06-25 11:37:04 +02:00
|
|
|
// recommended retail price
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxtprice = (oxtprice / ? * ?) WHERE oxshopid = ? AND (oxvat IS NULL)',
|
2020-06-25 11:37:04 +02:00
|
|
|
|
|
|
|
// varminprices
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxvarminprice = (oxvarminprice / ? * ?) WHERE oxshopid = ? AND (oxvat IS NULL)',
|
2020-06-25 11:37:04 +02:00
|
|
|
// varmaxprices
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxvarmaxprice = (oxvarmaxprice / ? * ?) WHERE oxshopid = ? AND (oxvat IS NULL)'
|
2020-06-25 11:37:04 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
public $baseQueriesCustomTax = [
|
|
|
|
//'UPDATE oxarticles SET oxprice = (oxprice / 1.19 * 1.16) WHERE oxshopid = 'oxbaseshop' AND (oxvat IN(16, 19));',
|
|
|
|
// default prices
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxprice = (oxprice / ? * ?) WHERE oxshopid = ? AND (oxvat IN(?, ?))',
|
2020-06-25 11:37:04 +02:00
|
|
|
// recommended retail price
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxtprice = (oxtprice / ? * ?) WHERE oxshopid = ? AND (oxvat IN(?, ?))',
|
2020-06-25 11:37:04 +02:00
|
|
|
|
|
|
|
// varminprices
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxvarminprice = (oxvarminprice / ? * ?) WHERE oxshopid = ? AND (oxvat IN(?, ?))',
|
2020-06-25 11:37:04 +02:00
|
|
|
// varmaxprices
|
2020-06-25 15:45:12 +02:00
|
|
|
'UPDATE oxarticles SET oxvarmaxprice = (oxvarmaxprice / ? * ?) WHERE oxshopid = ? AND (oxvat IN(?, ?))'
|
2020-06-25 11:37:04 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
if (false === $this->isInExecutableTimeRange()) {
|
|
|
|
trigger_error("script shouldn't run outside the defined time range", E_USER_WARNING);
|
|
|
|
die();
|
|
|
|
};
|
|
|
|
|
|
|
|
$this->changeArticlePrices();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function changeArticlePrices()
|
|
|
|
{
|
2020-06-25 12:01:07 +02:00
|
|
|
$shop = new \oxShop();
|
2020-06-25 11:37:04 +02:00
|
|
|
|
|
|
|
// use shop list, when parameter -d is set
|
|
|
|
$opts = getopt("s:");
|
|
|
|
|
|
|
|
$where = isset($opts['s']) ?
|
|
|
|
"oxid IN (".implode(', ', array_map(
|
2020-06-25 12:01:07 +02:00
|
|
|
function ($a) {return \oxDb::getDb()->quote(trim($a));},
|
2020-06-25 11:37:04 +02:00
|
|
|
explode(',', $opts['s']))
|
|
|
|
).")" :
|
|
|
|
"1";
|
|
|
|
|
|
|
|
$q = "SELECT oxid FROM " . $shop->getCoreTableName() . " WHERE ".$where ;
|
|
|
|
|
2020-06-25 12:01:07 +02:00
|
|
|
foreach ( \oxDb::getDb(\oxDb::FETCH_MODE_ASSOC)->getAll( $q ) as $record ) {
|
2020-06-25 11:37:04 +02:00
|
|
|
$shopId = (int) $record["oxid"];
|
|
|
|
|
|
|
|
$count = 0;
|
|
|
|
|
|
|
|
$count += $this->changeSubshopArticlePricesDefaultTax($shopId);
|
|
|
|
$count += $this->changeSubshopArticlePricesCustomTax($shopId);
|
|
|
|
|
|
|
|
echo "$count article prices in shop $shopId changed.".PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function changeSubshopArticlePricesDefaultTax($shopId)
|
|
|
|
{
|
|
|
|
$count = 0;
|
|
|
|
|
2020-06-25 15:45:12 +02:00
|
|
|
$oCurrConfig = oxRegistry::getConfig();
|
2020-06-25 11:37:04 +02:00
|
|
|
|
|
|
|
$oldTaxRate = (int) $oCurrConfig->getConfigParam('dDefaultVAT');
|
|
|
|
$newTaxRate = $this->rateChanges[$oldTaxRate];
|
|
|
|
|
|
|
|
if ($newTaxRate === null) {
|
|
|
|
$flipped = array_flip($this->rateChanges);
|
|
|
|
$oldTaxRate = $flipped[(int) $oCurrConfig->getConfigParam('dDefaultVAT')];
|
|
|
|
$newTaxRate = $this->rateChanges[$oldTaxRate];
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($this->baseQueriesDefaultTax as $query) {
|
2020-06-25 12:01:07 +02:00
|
|
|
$db = \oxDb::getDb(\oxDb::FETCH_MODE_ASSOC);
|
2020-06-25 11:37:04 +02:00
|
|
|
|
2020-06-25 15:45:12 +02:00
|
|
|
$paramLength = substr_count($query, '?');
|
|
|
|
|
|
|
|
$allQueryParameters = [
|
|
|
|
1 + ($oldTaxRate / 100),
|
|
|
|
1 + ($newTaxRate / 100),
|
|
|
|
$shopId,
|
|
|
|
$oldTaxRate,
|
|
|
|
$newTaxRate,
|
2020-06-25 11:37:04 +02:00
|
|
|
];
|
|
|
|
|
2020-06-25 15:45:12 +02:00
|
|
|
$queryParameters = array_slice($allQueryParameters, 0, $paramLength);
|
|
|
|
|
2020-06-25 11:37:04 +02:00
|
|
|
$count += $db->execute($query, $queryParameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function changeSubshopArticlePricesCustomTax($shopId)
|
|
|
|
{
|
|
|
|
$count = 0;
|
|
|
|
foreach ($this->baseQueriesCustomTax as $query) {
|
|
|
|
foreach ($this->rateChanges as $oldTaxRate => $newTaxRate) {
|
2020-06-25 12:01:07 +02:00
|
|
|
$db = \oxDb::getDb(\oxDb::FETCH_MODE_ASSOC);
|
2020-06-25 11:37:04 +02:00
|
|
|
|
2020-06-25 15:45:12 +02:00
|
|
|
$paramLength = substr_count($query, '?');
|
|
|
|
|
|
|
|
$allQueryParameters = [
|
|
|
|
1 + ($oldTaxRate / 100),
|
|
|
|
1 + ($newTaxRate / 100),
|
|
|
|
$shopId,
|
|
|
|
$oldTaxRate,
|
|
|
|
$newTaxRate,
|
2020-06-25 11:37:04 +02:00
|
|
|
];
|
|
|
|
|
2020-06-25 15:45:12 +02:00
|
|
|
$queryParameters = array_slice($allQueryParameters, 0, $paramLength);
|
|
|
|
|
2020-06-25 11:37:04 +02:00
|
|
|
$count += $db->execute($query, $queryParameters);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $count;
|
|
|
|
}
|
|
|
|
}
|