Skip to content

Commit be7175b

Browse files
author
stasiukaitis-saulius
committed
ESDEV-4774 Change updateProductAmountInBasket to changeBasket
Rewrite method that it would be driver and theme agnostic. Rename method to match already existing logic etc. addToBasket
1 parent c06dc1d commit be7175b

2 files changed

Lines changed: 33 additions & 32 deletions

File tree

README.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,17 @@ Add article to basket:
353353
// This will add article with ID 1001 to basket.
354354
$this->addToBasket("1001");
355355
356-
Update items amount in basket:
356+
Update items amount in basket: *(Note that item must be in basket in order to change it)*
357357

358358
.. code:: php
359359
360360
// This will update article with ID 1001 in basket to have 2 items.
361-
$this->updateProductAmountInBasket("1001", 2);
361+
$this->changeBasket("1001", 2);
362+
363+
.. code:: php
364+
365+
// This will remove an item from basket.
366+
$this->changeBasket("1001", 0);
362367
363368
Login user in front end side:
364369

library/AcceptanceTestCase.php

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public function openArticle($articleId, $clearCache = false, $shopId = null)
421421
}
422422

423423
/**
424-
* Adds article to basket
424+
* Adds article to basket.
425425
*
426426
* @param string $articleId Article id
427427
* @param int $amount Amount of items to add
@@ -451,40 +451,36 @@ public function addToBasket(
451451
$this->openNewWindow($this->_getShopUrl($aParams, $shopId), false);
452452
}
453453

454+
454455
/**
455-
* Update basket with new amount for the product.
456-
* Add needed amount or 0 to delete item from the basket.
456+
* Change product in basket.
457457
*
458-
* @param string $productId oxid of the product.
459-
* @param int $itemsAmount amount of the product.
458+
* @param string $articleId Article id
459+
* @param int $amount Amount of items to add
460+
* @param string $controller Controller name which should be opened after article is added
461+
* @param array $additionalParams Additional parameters (like persparam[details] for label)
462+
* @param int $shopId Shop id
460463
*/
461-
public function updateProductAmountInBasket($productId, $itemsAmount)
462-
{
463-
$this->openBasket();
464-
$this->getHtmlSource();
465-
466-
$basket = new \OxidEsales\Eshop\Application\Model\Basket();
467-
$itemId = $basket->getItemKey($productId);
468-
469-
// There is a bug in goutte while clicking on button in a form with more than one button:
470-
// only first button is available. In this case the third button is needed.
471-
// Bug is in BrowserKitDriver->click($xpath) where $this->getCrawler()->filterXPath($xpath) is called.
472-
// It returns a form which later on throws an exception.
473-
// This code gets a form and push it without need to click a button.
474-
if ($this->currentMinkDriver === "goutte") {
475-
$updateButton = $this->getElement("//button[@id='basketRemove']");
476-
$client = $updateButton->getSession()->getDriver()->getClient();
477-
$updateItemsForm = $client->getCrawler()->filterXPath("//form[@name='basket']")->form();
478-
$client->submit($updateItemsForm, ['aproducts[' . $itemId . '][am]' => $itemsAmount]);
479-
} else {
480-
$amountInput = $this->getElement("//input[@name='aproducts[$itemId][am]']");
481-
$amountInput->setValue($itemsAmount);
464+
public function changeBasket(
465+
$articleId,
466+
$amount = 1,
467+
$controller = 'basket',
468+
$additionalParams = array(),
469+
$shopId = null
470+
) {
471+
$input = $this->getElement('stoken', false);
472+
if ($input) {
473+
$params['stoken'] = $input->getValue();
474+
}
475+
$params['cl'] = $controller;
476+
$params['fnc'] = 'changebasket';
477+
$params['aid'] = $articleId;
478+
$params['am'] = $amount;
479+
$params['anid'] = $articleId;
482480

483-
$productSelector = $this->getElement("//input[@name='aproducts[$itemId][remove]']");
484-
$productSelector->check();
481+
$params = array_merge($params, $additionalParams);
485482

486-
$this->clickAndWait("//button[@id='basketUpdate']");
487-
}
483+
$this->openNewWindow($this->_getShopUrl($params, $shopId), false);
488484
}
489485

490486
/**

0 commit comments

Comments
 (0)