@@ -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