8
0
Fork 0

make article price adjustment scripts compatible to OXID 4.10 / 5.3

This commit is contained in:
Daniel Seifert 2020-06-25 12:01:07 +02:00
parent f4d7c8ef5f
commit db2d8cb09a
Signed by: DanielS
GPG Key ID: 8A7C4C6ED1915C6F
10 changed files with 32 additions and 38 deletions

View File

@ -62,7 +62,7 @@ Ein Einsatz in älteren Shopversionen ist vor dem Livebetrieb zwingend auf Verwe
Kopieren Sie den Inhalt des `copy_this`-Ordners in Ihren Shopordner. Achten Sie darauf, auch die verborgene .htaccess mitzukopieren, dass die Scripte nicht über den Browser von außen erreichbar sind.
Vergeben Sie den beiden Scripten im Ordner `_taxRates/bin` Ausführungsrechte.
Vergeben Sie den Scripten im Ordner `_taxRates/bin` Ausführungsrechte.
## Ausführung
@ -86,13 +86,13 @@ Nutzen Sie für die Preisanpassungen die folgenden Scripte als Cronjob zum passe
um die Artikelpreise zu senken::
```
[ Shoppfad ]/vendor/bin/reduceArticlePrices
[ Shoppfad ]/_taxRates/bin/reduceArticlePrices
```
um die Artikelpreise zurückzusetzen:
```
[ Shoppfad ]/vendor/bin/raiseArtikelPrices
[ Shoppfad ]/_taxRates/bin/raiseArtikelPrices
```
Führen Sie die Preisanpassungsscripte nur ein einziges Mal aus, da die Preise sonst mehrfach gesenkt / erhöht werden.

View File

@ -15,10 +15,7 @@
namespace D3\TaxRatesAdjustment\Models;
use D3\ModCfg\Application\Model\d3database;
use OxidEsales\Eshop\Application\Model\Shop;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\DatabaseProvider;
require_once('genericAbstract.php');
abstract class articlePricesAbstract extends genericAbstract
{
@ -48,10 +45,6 @@ abstract class articlePricesAbstract extends genericAbstract
'UPDATE oxarticles SET oxvarmaxprice = (oxvarmaxprice / :oldTaxPercent * :newTaxPercent) WHERE oxshopid = :shopid AND (oxvat IN(:oldTaxRate, :newTaxRate))'
];
/**
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseErrorException
*/
public function run()
{
if (false === $this->isInExecutableTimeRange()) {
@ -62,27 +55,23 @@ abstract class articlePricesAbstract extends genericAbstract
$this->changeArticlePrices();
}
/**
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseErrorException
*/
public function changeArticlePrices()
{
$shop = new Shop();
$shop = new \oxShop();
// use shop list, when parameter -d is set
$opts = getopt("s:");
$where = isset($opts['s']) ?
"oxid IN (".implode(', ', array_map(
function ($a) {return DatabaseProvider::getDb()->quote(trim($a));},
function ($a) {return \oxDb::getDb()->quote(trim($a));},
explode(',', $opts['s']))
).")" :
"1";
$q = "SELECT oxid FROM " . $shop->getCoreTableName() . " WHERE ".$where ;
foreach ( DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC )->getAll( $q ) as $record ) {
foreach ( \oxDb::getDb(\oxDb::FETCH_MODE_ASSOC)->getAll( $q ) as $record ) {
$shopId = (int) $record["oxid"];
$count = 0;
@ -99,7 +88,7 @@ abstract class articlePricesAbstract extends genericAbstract
{
$count = 0;
$oCurrConfig = new Config();
$oCurrConfig = new \oxConfig();
$oldTaxRate = (int) $oCurrConfig->getConfigParam('dDefaultVAT');
$newTaxRate = $this->rateChanges[$oldTaxRate];
@ -111,7 +100,7 @@ abstract class articlePricesAbstract extends genericAbstract
}
foreach ($this->baseQueriesDefaultTax as $query) {
$db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
$db = \oxDb::getDb(\oxDb::FETCH_MODE_ASSOC);
$queryParameters = [
'shopid' => $shopId,
@ -132,7 +121,7 @@ abstract class articlePricesAbstract extends genericAbstract
$count = 0;
foreach ($this->baseQueriesCustomTax as $query) {
foreach ($this->rateChanges as $oldTaxRate => $newTaxRate) {
$db = DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
$db = \oxDb::getDb(\oxDb::FETCH_MODE_ASSOC);
$queryParameters = [
'shopid' => $shopId,

View File

@ -15,9 +15,6 @@
namespace D3\TaxRatesAdjustment\Models;
use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry;
abstract class genericAbstract
{
public $rateChanges = [
@ -48,18 +45,18 @@ abstract class genericAbstract
*/
public function switchToShop($id)
{
if (Registry::getConfig()->isMall()
&& $id != Registry::getConfig()->getActiveShop()->getId()
if (oxRegistry::getConfig()->isMall()
&& $id != oxRegistry::getConfig()->getActiveShop()->getId()
) {
/** @var Config $oNewConf */
$oNewConf = new Config();
/** @var oxConfig $oNewConf */
$oNewConf = new oxConfig();
$oNewConf->setShopId($id);
$oNewConf->init();
Registry::getConfig()->onShopChange();
Registry::getSession()->setVariable('actshop', $id);
Registry::getSession()->setVariable('currentadminshop', $id);
Registry::getConfig()->setShopId($id);
oxRegistry::getConfig()->onShopChange();
oxRegistry::getSession()->setVariable('actshop', $id);
oxRegistry::getSession()->setVariable('currentadminshop', $id);
oxRegistry::getConfig()->setShopId($id);
}
}
}

View File

@ -15,6 +15,9 @@
namespace D3\TaxRatesAdjustment\Models;
require_once('articlePricesAbstract.php');
require_once('raiseTrait.php');
class raiseArticlePrices extends articlePricesAbstract
{
use raiseTrait;

View File

@ -15,7 +15,8 @@
namespace D3\TaxRatesAdjustment\Models;
require 'taxRateAbstract.php';
require_once 'taxRateAbstract.php';
require_once 'raiseTrait.php';
class raiseTaxRate extends taxRateAbstract
{

View File

@ -15,6 +15,9 @@
namespace D3\TaxRatesAdjustment\Models;
require_once('articlePricesAbstract.php');
require_once('reduceTrait.php');
class reduceArticlePrices extends articlePricesAbstract
{
use reduceTrait;

View File

@ -15,7 +15,8 @@
namespace D3\TaxRatesAdjustment\Models;
require 'taxRateAbstract.php';
require_once 'taxRateAbstract.php';
require_once 'reduceTrait.php';
class reduceTaxRate extends taxRateAbstract
{

View File

@ -21,12 +21,10 @@ use oxDb;
use oxRegistry;
use oxShop;
require_once('genericAbstract.php');
abstract class taxRateAbstract extends genericAbstract
{
/**
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseConnectionException
* @throws \OxidEsales\Eshop\Core\Exception\DatabaseErrorException
*/
public function run()
{
if (false === $this->isInExecutableTimeRange()) {

View File

@ -6,6 +6,7 @@ $currentDirectory = __DIR__ . '/';
$filePath = $currentDirectory . $filePath;
require($filePath);
require(__DIR__.'/../Models/raiseArticlePrices.php');
$change = new \D3\TaxRatesAdjustment\Models\raiseArticlePrices();
try {

View File

@ -6,6 +6,7 @@ $currentDirectory = __DIR__ . '/';
$filePath = $currentDirectory . $filePath;
require($filePath);
require(__DIR__.'/../Models/reduceArticlePrices.php');
$change = new \D3\TaxRatesAdjustment\Models\reduceArticlePrices();
try {