Skip to content

Commit

Permalink
Merge pull request #213 from OXID-eSales/UNZER-278_UnzerOrderNumberSe…
Browse files Browse the repository at this point in the history
…archable

Unzer 278 unzer order number searchable
  • Loading branch information
mariolorenz authored Nov 23, 2023
2 parents 5a750bb + 2098f6e commit bfcb91c
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 34 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- [0007553](https://bugs.oxid-esales.com/view.php?id=7553) revert this task because, it is possible to have different billing and delivery addresses for invoice purchases (Paylater)
- Discounts with time restrictions may not be invalidated directly in the checkout...
-
- provided additional Order-Number is searchable

## [1.1.3] - 2023-11-14

- [0007526](https://bugs.oxid-esales.com/view.php?id=7526) Order would be saved only, if everything is correct. In all other cases redirect to checkout
Expand Down
9 changes: 7 additions & 2 deletions Tests/PhpStan/phpstan-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class_alias(
\OxidSolutionCatalysts\Unzer\Controller\Admin\OrderMain_parent::class
);

class_alias(
\OxidEsales\Eshop\Application\Controller\Admin\OrderList::class,
\OxidSolutionCatalysts\Unzer\Controller\Admin\OrderList_parent::class
);

class_alias(
\OxidEsales\Eshop\Application\Controller\OrderController::class,
\OxidSolutionCatalysts\Unzer\Controller\OrderController_parent::class
Expand Down Expand Up @@ -57,6 +62,6 @@ class_alias(
);

class_alias(
\OxidEsales\Eshop\Application\Model\PaymentGateway::class,
\OxidSolutionCatalysts\Unzer\Model\PaymentGateway_parent::class
\OxidEsales\Eshop\Application\Model\DiscountList::class,
\OxidSolutionCatalysts\Unzer\Model\DiscountList_parent::class
);
1 change: 1 addition & 0 deletions Tests/PhpStan/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
parameters:
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
bootstrapFiles:
- phpstan-bootstrap.php
level: max
Expand Down
3 changes: 2 additions & 1 deletion metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OxidSolutionCatalysts\Unzer\Controller\Admin\AdminOrderController;
use OxidSolutionCatalysts\Unzer\Controller\Admin\ModuleConfiguration;
use OxidSolutionCatalysts\Unzer\Controller\Admin\OrderMain;
use OxidSolutionCatalysts\Unzer\Controller\Admin\OrderList;
use OxidSolutionCatalysts\Unzer\Controller\ApplePayCallbackController;
use OxidSolutionCatalysts\Unzer\Controller\DispatcherController;
use OxidSolutionCatalysts\Unzer\Controller\InstallmentController;
Expand All @@ -21,7 +22,6 @@
use OxidSolutionCatalysts\Unzer\Core\Config;
use OxidSolutionCatalysts\Unzer\Core\ShopControl;
use OxidSolutionCatalysts\Unzer\Core\ViewConfig;
use OxidSolutionCatalysts\Unzer\Model\PaymentGateway;
use OxidSolutionCatalysts\Unzer\Model\Article;
use OxidSolutionCatalysts\Unzer\Model\Order;
use OxidSolutionCatalysts\Unzer\Model\Payment;
Expand Down Expand Up @@ -67,6 +67,7 @@
\OxidEsales\Eshop\Core\ShopControl::class => ShopControl::class,
\OxidEsales\Eshop\Application\Controller\Admin\ModuleConfiguration::class => ModuleConfiguration::class,
\OxidEsales\Eshop\Application\Controller\Admin\OrderMain::class => OrderMain::class,
\OxidEsales\Eshop\Application\Controller\Admin\OrderList::class => OrderList::class,
\OxidEsales\Eshop\Application\Model\Article::class => Article::class,
],
'controllers' => [
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Admin/AdminOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ protected function addAuthorizationViewData(Authorization $authorization): void
$this->_aViewData["AuthId"] = $authorization->getId();
$this->_aViewData["AuthAmount"] = $authorization->getAmount();
$holderData = [];
$holderData['bic'] = $authorization->getBic();
$holderData['iban'] = $authorization->getIban();
$holderData['descriptor'] = $authorization->getDescriptor();
$holderData['holder'] = $authorization->getHolder();
$holderData['bic'] = $authorization->getBic();
$holderData['iban'] = $authorization->getIban();
$holderData['descriptor'] = $authorization->getDescriptor();
$holderData['holder'] = $authorization->getHolder();
$this->_aViewData["holderData"] = $holderData;
}

Expand Down
53 changes: 53 additions & 0 deletions src/Controller/Admin/OrderList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace OxidSolutionCatalysts\Unzer\Controller\Admin;

use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Registry;

class OrderList extends OrderList_parent
{
/**
* Adding folder check
* bi *
* @param array $whereQuery SQL condition array
* @param string $fullQuery SQL query string
*
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return string
*/
protected function _prepareWhereQuery($whereQuery, $fullQuery)
{
// seperate oxordernr
$orderNrSearch = '';
if (isset($whereQuery['oxorder.oxordernr'])) {
$orderNrSearch = $whereQuery['oxorder.oxordernr'];
unset($whereQuery['oxorder.oxordernr']);
}

$database = DatabaseProvider::getDb();
$query = parent::_prepareWhereQuery($whereQuery, $fullQuery);
$config = $this->getConfig();
$folders = $config->getConfigParam('aOrderfolder');
$folder = Registry::getConfig()->getRequestParameter('folder');
// Searching for empty oxfolder fields
if ($folder && $folder !== '-1') {
$query .= " and ( oxorder.oxfolder = " . $database->quote($folder) . " )";
} elseif (!$folder && is_array($folders)) {
$folderNames = array_keys($folders);
$query .= " and ( oxorder.oxfolder = " . $database->quote($folderNames[0]) . " )";
}

// glue oxordernr
if ($orderNrSearch) {
$oxOrderNr = $database->quoteIdentifier("oxorder.oxordernr");
$oxUnzerOrderNr = $database->quoteIdentifier("oxorder.oxunzerordernr");
$orderNrValue = $database->quote($orderNrSearch);
$query .= " and ({$oxOrderNr} like {$orderNrValue} or {$oxUnzerOrderNr} like {$orderNrValue}) ";
}

return $query;
}
}
81 changes: 55 additions & 26 deletions src/Model/DiscountList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,31 @@

namespace OxidSolutionCatalysts\Unzer\Model;

use OxidEsales\Eshop\Application\Model\Article;
use OxidEsales\Eshop\Application\Model\Groups;
use OxidEsales\Eshop\Application\Model\User;
use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Model\ListModel;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\Eshop\Application\Model\DiscountList as CoreDisCountList;

class DiscountList extends DiscountList_parent
{


/**
* Returns array of discounts that can be globally (transparently) applied
*
* @param \OxidEsales\Eshop\Application\Model\Article $oArticle article object
* @param \OxidEsales\Eshop\Application\Model\User $oUser oxuser object (optional)
* @param Article $oArticle article object
* @param User $oUser oxuser object (optional)
*
* @return array
*/
public function getArticleDiscounts($oArticle, $oUser = null)
{
$aList = [];
$this->forceReload();
$aDiscList = $this->_getList($oUser)->getArray();
/** @var CoreDisCountList $oDiscList */
$oDiscList = $this->_getList($oUser);
$aDiscList = $oDiscList->getArray();
foreach ($aDiscList as $oDiscount) {
if ($oDiscount->isForArticle($oArticle)) {
$aList[$oDiscount->getId()] = $oDiscount;
Expand All @@ -39,33 +45,35 @@ public function getArticleDiscounts($oArticle, $oUser = null)
/**
* Creates discount list filter SQL to load current state discount list
*
* @param \OxidEsales\Eshop\Application\Model\User $oUser user object
* @SuppressWarnings(PHPMD.StaticAccess)
*
* @return string
* @deprecated underscore prefix violates PSR12, will be renamed to "getFilterSelect" in next major
* @inheritdoc
*/
protected function _getFilterSelect($oUser) // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore
protected function _getFilterSelect($oUser)
{
$oBaseObject = $this->getBaseObject();
$bDisableSqlActiveSnippet = Registry::getSession()->getVariable('disableSqlActiveSnippet');
$bDisableSqlActive = Registry::getSession()->getVariable('disableSqlActiveSnippet');
$sTable = $oBaseObject->getViewName();
$sQ = "select " . $oBaseObject->getSelectFields() . " from $sTable ";
$sQ .= true === $bDisableSqlActiveSnippet ? "where 1=1 " : "where " . $oBaseObject->getSqlActiveSnippet() . ' ';

$sSql = "select " . $oBaseObject->getSelectFields() . " from $sTable where 1 ";
$sSql .= false === $bDisableSqlActive ? $oBaseObject->getSqlActiveSnippet() . ' ' : '';

// defining initial filter parameters
$sUserId = null;
$sGroupIds = null;
$sCountryId = $this->getCountryId($oUser);
$oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$oDb = DatabaseProvider::getDb();

// checking for current session user which gives additional restrictions for user itself, users group and country
// checking for current session user which gives additional restrictions for user itself,
// users group and country
if ($oUser) {
// user ID
$sUserId = $oUser->getId();

// user group ids
foreach ($oUser->getUserGroups() as $oGroup) {
/** @var ListModel $userGroups */
$userGroups = $oUser->getUserGroups();
/** @var Groups $oGroup */
foreach ($userGroups as $oGroup) {
if ($sGroupIds) {
$sGroupIds .= ', ';
}
Expand All @@ -77,24 +85,45 @@ protected function _getFilterSelect($oUser) // phpcs:ignore PSR2.Methods.MethodD
$sGroupTable = getViewName('oxgroups');
$sCountryTable = getViewName('oxcountry');

$sCountrySql = $sCountryId ? "EXISTS(select oxobject2discount.oxid from oxobject2discount where oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxcountry' and oxobject2discount.OXOBJECTID=" . $oDb->quote($sCountryId) . ")" : '0';
$sUserSql = $sUserId ? "EXISTS(select oxobject2discount.oxid from oxobject2discount where oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxuser' and oxobject2discount.OXOBJECTID=" . $oDb->quote($sUserId) . ")" : '0';
$sGroupSql = $sGroupIds ? "EXISTS(select oxobject2discount.oxid from oxobject2discount where oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxgroups' and oxobject2discount.OXOBJECTID in ($sGroupIds) )" : '0';

$sQ .= "and (
if(EXISTS(select 1 from oxobject2discount, $sCountryTable where $sCountryTable.oxid=oxobject2discount.oxobjectid and oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxcountry' LIMIT 1),
$sCountrySql = $sCountryId ?
"EXISTS(select oxobject2discount.oxid from oxobject2discount where
oxobject2discount.OXDISCOUNTID = $sTable.OXID and oxobject2discount.oxtype = 'oxcountry' and
oxobject2discount.OXOBJECTID = " . $oDb->quote($sCountryId) . ")" :
'0';
$sUserSql = $sUserId ?
"EXISTS(select oxo bject2discount.oxid from oxobject2discount where
oxobject2discount.OXDISCOUNTID = $sTable.OXID and oxobject2discount.oxtype = 'oxuser' and
oxobject2discount.OXOBJECTID = " . $oDb->quote($sUserId) . ")" :
'0';
$sGroupSql = $sGroupIds ?
"EXISTS(select oxobject2discount.oxid from oxobject2discount where
oxobject2discount.OXDISCOUNTID = $sTable.OXID and oxobject2discount.oxtype = 'oxgroups' and
oxobject2discount.OXOBJECTID in ($sGroupIds) )" :
'0';

$sSql .= "and (
if(EXISTS(select 1 from oxobject2discount, $sCountryTable where
$sCountryTable.oxid = oxobject2discount.oxobjectid and
oxobject2discount.OXDISCOUNTID = $sTable.OXID and
oxobject2discount.oxtype = 'oxcountry' LIMIT 1),
$sCountrySql,
1) &&
if(EXISTS(select 1 from oxobject2discount, $sUserTable where $sUserTable.oxid=oxobject2discount.oxobjectid and oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxuser' LIMIT 1),
if(EXISTS(select 1 from oxobject2discount, $sUserTable where
$sUserTable.oxid = oxobject2discount.oxobjectid and
oxobject2discount.OXDISCOUNTID = $sTable.OXID and
oxobject2discount.oxtype = 'oxuser' LIMIT 1),
$sUserSql,
1) &&
if(EXISTS(select 1 from oxobject2discount, $sGroupTable where $sGroupTable.oxid=oxobject2discount.oxobjectid and oxobject2discount.OXDISCOUNTID=$sTable.OXID and oxobject2discount.oxtype='oxgroups' LIMIT 1),
if(EXISTS(select 1 from oxobject2discount, $sGroupTable where
$sGroupTable.oxid = oxobject2discount.oxobjectid and
oxobject2discount.OXDISCOUNTID = $sTable.OXID and
oxobject2discount.oxtype = 'oxgroups' LIMIT 1),
$sGroupSql,
1)
)";

$sQ .= " order by $sTable.oxsort ";
$sSql .= " order by $sTable.oxsort ";

return $sQ;
return $sSql;
}
}

0 comments on commit bfcb91c

Please sign in to comment.