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

6539: split selectlists and varselect #507

Closed
Closed
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
5 changes: 4 additions & 1 deletion source/Application/Model/Order.php
Expand Up @@ -828,6 +828,9 @@ protected function _setOrderArticles($aArticleList)
}
$sSelList .= "{$oItem->name} : {$oItem->value}";
}
if ($sSelList !== '' && $oContent->getVarSelect() !== '') {
$sSelList .= ' ||';
}
}

$oOrderArticle = oxNew(\OxidEsales\Eshop\Application\Model\OrderArticle::class);
Expand All @@ -836,7 +839,7 @@ protected function _setOrderArticles($aArticleList)
$oOrderArticle->setId();

$oOrderArticle->oxorderarticles__oxartnum = clone $oProduct->oxarticles__oxartnum;
$oOrderArticle->oxorderarticles__oxselvariant = new \OxidEsales\Eshop\Core\Field(trim($sSelList . ' ' . $oProduct->oxarticles__oxvarselect->getRawValue()), \OxidEsales\Eshop\Core\Field::T_RAW);
$oOrderArticle->oxorderarticles__oxselvariant = new \OxidEsales\Eshop\Core\Field(trim($sSelList . ' ' . $oContent->getVarSelect()), \OxidEsales\Eshop\Core\Field::T_RAW);
$oOrderArticle->oxorderarticles__oxshortdesc = new \OxidEsales\Eshop\Core\Field($oProduct->oxarticles__oxshortdesc->getRawValue(), \OxidEsales\Eshop\Core\Field::T_RAW);
// #M974: duplicated entries for the name of variants in orders
$oOrderArticle->oxorderarticles__oxtitle = new \OxidEsales\Eshop\Core\Field(trim($oProduct->oxarticles__oxtitle->getRawValue()), \OxidEsales\Eshop\Core\Field::T_RAW);
Expand Down
2 changes: 2 additions & 0 deletions source/Application/Model/OrderArticle.php
Expand Up @@ -388,6 +388,7 @@ public function getOrderArticleSelectList($sArtId = null, $sOrderArtSelList = nu
{
if ($this->_aOrderArticleSelList === null) {
$sOrderArtSelList = $sOrderArtSelList ? $sOrderArtSelList : $this->oxorderarticles__oxselvariant->value;
$sOrderArtSelList = explode(' || ', $sOrderArtSelList)[0];

$aRet = [];

Expand Down Expand Up @@ -418,6 +419,7 @@ public function getOrderArticleSelectList($sArtId = null, $sOrderArtSelList = nu
if ($oStr->strtolower($oSel->name) == $sOrderArtSelValue) {
// found, adding to return array
$aRet[$iSelListNum] = $iSelValueNum;
break;
}
//next article list item
$iSelValueNum++;
Expand Down
49 changes: 49 additions & 0 deletions tests/Unit/Application/Model/OrderTest.php
Expand Up @@ -2185,6 +2185,55 @@ public function testSetOrderArticlesWithTwoChoosenSelectList()
$this->assertEquals('Bar-Set ABSINTH', $oOrderArticles[1]->oxorderarticles__oxtitle->value);
}

public function testSetOrderArticlesWithTwoChoosenSelectListAndAVariant()
{
$aChosenSelectlist[0] = new stdClass();
$aChosenSelectlist[0]->name = 'selectName';
$aChosenSelectlist[0]->value = 'selectValue';

$aChosenSelectlist2[0] = new stdClass();
$aChosenSelectlist2[0]->name = 'selectName2';
$aChosenSelectlist2[0]->value = 'selectValue2';

$sVarSelect = 'red | S';

// simulating basket
$oPrice = oxNew('oxPrice');
$oPrice->setPrice(119, 19);

$oBasketItem = $this->getProxyClass("oxBasketItem");
$oBasketItem->setNonPublicVar('_sProductId', '1126');
$oBasketItem->setNonPublicVar('_oPrice', $oPrice);
$oBasketItem->setNonPublicVar('_oUnitPrice', $oPrice);
$oBasketItem->setNonPublicVar('_aChosenSelectlist', $aChosenSelectlist);
$aBasketItems[] = $oBasketItem;

$oBasketItem2 = $this->getProxyClass("oxBasketItem");
$oBasketItem2->setNonPublicVar('_sProductId', '1126');
$oBasketItem2->setNonPublicVar('_oPrice', $oPrice);
$oBasketItem2->setNonPublicVar('_oUnitPrice', $oPrice);
$oBasketItem2->setNonPublicVar('_aChosenSelectlist', $aChosenSelectlist2);
$oBasketItem2->setNonPublicVar('_sVarSelect', $sVarSelect);
$aBasketItems[] = $oBasketItem2;


$oOrder = $this->getProxyClass("oxOrder");
$oOrder->setId('_testOrderId');
$oOrder->UNITsetOrderArticles($aBasketItems);

$oArticles = $oOrder->getNonPublicVar('_oArticles');

$i = 0;
foreach ($oArticles as $oArticle) {
$oOrderArticles[$i++] = $oArticle;
}

$this->assertEquals('selectName : selectValue', $oOrderArticles[0]->oxorderarticles__oxselvariant->value);
$this->assertEquals('selectName2 : selectValue2 || red | S', $oOrderArticles[1]->oxorderarticles__oxselvariant->value);
$this->assertEquals('Bar-Set ABSINTH', $oOrderArticles[0]->oxorderarticles__oxtitle->value);
$this->assertEquals('Bar-Set ABSINTH', $oOrderArticles[1]->oxorderarticles__oxtitle->value);
}

public function testExecutePayment()
{
$oGateway = $this->getMock(\OxidEsales\Eshop\Application\Model\PaymentGateway::class, array('executePayment'));
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Application/Model/OrderarticleTest.php
Expand Up @@ -414,6 +414,11 @@ public function testMakeSelListArray()
$sFields = "Color : red, Material : wood ";
$oOrderArticle = oxNew('oxOrderArticle');
$this->assertEquals(array(0 => 0), $oOrderArticle->getOrderArticleSelectList('1126', $sFields));

// articles with selectlists and variants should work
$sFields = "Color : red || variantvalue1 | variantvalue2";
$oOrderArticle = oxNew('oxOrderArticle');
$this->assertEquals(array(0 => 0), $oOrderArticle->getOrderArticleSelectList('1126', $sFields));
}

public function testMakeSelListArrayPriceON()
Expand Down