Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6027 - Added a further SQL query part to check if the parent is buyable. #390

Merged
merged 2 commits into from Jun 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions source/Application/Controller/Admin/DiscountArticlesAjax.php
Expand Up @@ -87,12 +87,19 @@ protected function _getQuery()
if (!$sOxid && $sSynchOxid) {
$sQAdd = " from $sArticleTable where 1 ";
$sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArticleTable.oxparentid = '' ";

//#6027
//if we have variants then depending on config option the parent may be non buyable
//when the checkbox is checked, blVariantParentBuyable is true.
$sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : "and $sArticleTable.oxvarcount = 0";
} else {
// selected category ?
if ($sSynchOxid && $sOxid != $sSynchOxid) {
$sQAdd = " from $sO2CView left join $sArticleTable on ";
$sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? "($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)" : " $sArticleTable.oxid=$sO2CView.oxobjectid ";
$sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote($sOxid) . " and $sArticleTable.oxid is not null ";
//#6027
$sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : " and $sArticleTable.oxvarcount = 0";

// resetting
$sId = null;
Expand Down
7 changes: 7 additions & 0 deletions source/Application/Controller/Admin/DiscountItemAjax.php
Expand Up @@ -78,12 +78,19 @@ protected function _getQuery()
if (!$sOxid && $sSynchOxid) {
$sQAdd = " from $sArticleTable where 1 ";
$sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArticleTable.oxparentid = '' ";

//#6027
//if we have variants then depending on config option the parent may be non buyable
//when the checkbox is checked, blVariantParentBuyable is true.
$sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : "and $sArticleTable.oxvarcount = 0";
} else {
// selected category ?
if ($sSynchOxid && $sOxid != $sSynchOxid) {
$sQAdd = " from $sO2CView left join $sArticleTable on ";
$sQAdd .= $oConfig->getConfigParam('blVariantsSelection') ? "($sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid)" : " $sArticleTable.oxid=$sO2CView.oxobjectid ";
$sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote($sOxid) . " and $sArticleTable.oxid is not null ";
//#6027
$sQAdd .= $oConfig->getConfigParam('blVariantParentBuyable') ? '' : " and $sArticleTable.oxvarcount = 0";

// resetting
$sId = null;
Expand Down
Expand Up @@ -80,6 +80,31 @@ public function testGetQueryOxid()
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("oxid", $sOxid);
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', false);
$sArticleTable = getViewName("oxarticles");
$sO2CView = getViewName("oxobject2category");

$oView = oxNew('discount_articles_ajax');
$sQuery = "from $sO2CView left join $sArticleTable on $sArticleTable.oxid=$sO2CView.oxobjectid ";
$sQuery .= " where $sO2CView.oxcatnid = '_testOxid' and $sArticleTable.oxid is not null and ";
$sQuery .= "$sArticleTable.oxvarcount = 0 and ";
$sQuery .= " $sArticleTable.oxid not in ( select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
$sQuery .= " and oxobject2discount.oxdiscountid = '_testSynchoxid' and oxobject2discount.oxtype = 'oxarticles' )";
$this->assertEquals($sQuery, trim($oView->UNITgetQuery()));
}

/**
* DiscountArticlesAjax::_getQuery() test case
*
* @return null
*/
public function testGetQueryOxidParentIsBuyable()
{
$sOxid = '_testOxid';
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("oxid", $sOxid);
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', true);
$sArticleTable = getViewName("oxarticles");
$sO2CView = getViewName("oxobject2category");

Expand All @@ -100,6 +125,26 @@ public function testGetQuerySynchoxid()
{
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', false);
$sArticleTable = getViewName("oxarticles");

$oView = oxNew('discount_articles_ajax');
$sQuery = "from $sArticleTable where 1 and $sArticleTable.oxparentid = '' and $sArticleTable.oxvarcount = 0 and ";
$sQuery .= " $sArticleTable.oxid not in ( select $sArticleTable.oxid from oxobject2discount, $sArticleTable where $sArticleTable.oxid=oxobject2discount.oxobjectid ";
$sQuery .= " and oxobject2discount.oxdiscountid = '_testSynchoxid' and oxobject2discount.oxtype = 'oxarticles' )";
$this->assertEquals($sQuery, trim($oView->UNITgetQuery()));
}

/**
* DiscountArticlesAjax::_getQuery() test case
*
* @return null
*/
public function testGetQuerySynchoxidParentIsBuyable()
{
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', true);
$sArticleTable = getViewName("oxarticles");

$oView = oxNew('discount_articles_ajax');
Expand Down Expand Up @@ -169,8 +214,9 @@ public function testAddDiscArtAll()
$sSynchoxid = '_testDiscountNew';
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setRequestParameter("all", true);
$this->setConfigParam('blVariantParentBuyable', false);

$iCount = oxDb::getDb()->getOne("select count(oxid) from oxarticles where oxparentid = ''");
$iCount = oxDb::getDb()->getOne("select count(oxid) from oxarticles where oxparentid = '' and oxvarcount = 0");

$oView = oxNew('discount_articles_ajax');
$this->assertGreaterThan(0, $iCount);
Expand All @@ -180,4 +226,25 @@ public function testAddDiscArtAll()
$this->assertEquals($iCount, oxDb::getDb()->getOne("select count(oxid) from oxobject2discount where oxdiscountid='$sSynchoxid'"));
}

/**
* DiscountArticlesAjax::addDiscArt() test case
*
* @return null
*/
public function testAddDiscArtAllParentIsBuyable()
{
$sSynchoxid = '_testDiscountNewParentIsBuyable';
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setRequestParameter("all", true);
$this->setConfigParam('blVariantParentBuyable', true);

$iCount = oxDb::getDb()->getOne("select count(oxid) from oxarticles where oxparentid = ''");

$oView = oxNew('discount_articles_ajax');
$this->assertGreaterThan(0, $iCount);
$this->assertEquals(0, oxDb::getDb()->getOne("select count(oxid) from oxobject2discount where oxdiscountid='$sSynchoxid'"));

$oView->addDiscArt();
$this->assertEquals($iCount, oxDb::getDb()->getOne("select count(oxid) from oxobject2discount where oxdiscountid='$sSynchoxid'"));
}
}
48 changes: 48 additions & 0 deletions tests/Unit/Application/Controller/Admin/DiscountItemAjaxTest.php
Expand Up @@ -87,6 +87,33 @@ public function testGetQueryOxid()
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("oxid", $sOxid);
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', false);
$sArticleTable = getViewName("oxarticles");
$sO2CView = getViewName("oxobject2category");
$sDiscTable = getViewName('oxdiscount');

$oView = oxNew('discount_item_ajax');
$sQuery = "from $sO2CView left join $sArticleTable on $sArticleTable.oxid=$sO2CView.oxobjectid ";
$sQuery .= " where $sO2CView.oxcatnid = '_testOxid' and $sArticleTable.oxid is not null and ";
$sQuery .= "$sArticleTable.oxvarcount = 0 and ";
$sQuery .= " $sArticleTable.oxid not in ( select $sArticleTable.oxid from $sDiscTable, $sArticleTable where $sArticleTable.oxid=$sDiscTable.oxitmartid ";
$sQuery .= " and $sDiscTable.oxid = '_testSynchoxid' )";
$this->assertEquals($sQuery, trim($oView->UNITgetQuery()));
}


/**
* DiscountItemAjax::_getQuery() test case
*
* @return null
*/
public function testGetQueryOxidParentIsBuyable()
{
$sOxid = '_testOxid';
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("oxid", $sOxid);
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', true);
$sArticleTable = getViewName("oxarticles");
$sO2CView = getViewName("oxobject2category");
$sDiscTable = getViewName('oxdiscount');
Expand All @@ -108,6 +135,27 @@ public function testGetQuerySynchoxid()
{
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', false);
$sArticleTable = getViewName("oxarticles");
$sDiscTable = getViewName('oxdiscount');

$oView = oxNew('discount_item_ajax');
$sQuery = "from $sArticleTable where 1 and $sArticleTable.oxparentid = '' and $sArticleTable.oxvarcount = 0 and ";
$sQuery .= " $sArticleTable.oxid not in ( select $sArticleTable.oxid from $sDiscTable, $sArticleTable where $sArticleTable.oxid=$sDiscTable.oxitmartid ";
$sQuery .= " and $sDiscTable.oxid = '_testSynchoxid' )";
$this->assertEquals($sQuery, trim($oView->UNITgetQuery()));
}

/**
* DiscountItemAjax::_getQuery() test case
*
* @return null
*/
public function testGetQuerySynchoxidParentIsBuyable()
{
$sSynchoxid = '_testSynchoxid';
$this->setRequestParameter("synchoxid", $sSynchoxid);
$this->setConfigParam('blVariantParentBuyable', true);
$sArticleTable = getViewName("oxarticles");
$sDiscTable = getViewName('oxdiscount');

Expand Down