View Single Post
  #5  
Old 10-08-2019, 06:21 AM
 
Ed B. Ed B. is offline
 

X-Adept
  
Join Date: Apr 2016
Posts: 446
 

Default Re: Checkout Process

I thought this would be a children's game, but somehow I can't make this work.


So my idea is to add a button on ListItem, that is


skins/customer/modules/EdB/QuickBuy/items_list/product/parts/mybutton.twig
Code:
{## # # @ListChild (list="itemsList.product.grid.customer.tail", weight="99") #} {## # # @ListChild (list="itemsList.product.grid.customer.tail", weight="99") #} {{ widget('\\XLite\\Module\\EdB\\QuickBuy\\View\\Button\\Quick') }}
(this will add buttons for every article, even the ones that can't be ordered, but we can deal with this problem later).


The button widget looks like


Code:
<?php namespace XLite\Module\EdB\QuickBuy\View\Button; class Quick extends \XLite\View\Button\Regular /** * Go to checkout */ { /** * Get default label * * @return string */ protected function getDefaultLabel() { return 'Buy'; } protected function getDefaultAction() { return 'quickBuy'; } /** * Define widget parameters * * @return void */ protected function defineWidgetParams() { } /** * getDefaultStyle * * @return string */ protected function getDefaultStyle() { return $this->getCart()->checkCart() ? 'regular-main-button checkout' : 'regular-main-button disabled add2cart-disabled checkout'; }


Again, the button looks terribly ugly, but we can deal with it later. Normally, it only remains to define the function doActionQuickBuy() in the appropriate controller class,
that is


Code:
<?php namespace XLite\Module\EdB\QuickBuy\Controller\Customer; abstract class Cart extends XLite\Controller\Customer\Cart implements \XLite\Ba se\IDecorator { public function doActionQuickBuy() { echo "action!"; parent::doActionAdd(); $this->setReturnURL( $this->buildURL('checkout', '', array()) ); } }
(Probably one could have simply done
Code:
parent::doActionAdd(); parent::doActionCheckout();


However, this code produces the button, but clicking on the button does
nothing. Presumably because the regular button is for submitting a form, and there is no form. I have also tried to use "Link" class, but then I can't define "getDefaultAction". Another approach would be somehow to decorate

View/Product/ListItem.php to get a second button, the class use a method getAdd2CartBlockWidget to show the "add to cart" button, but I fail to see how to use this method to produce another button. or call twice this method within the class.


Would anyone know how to do this?


[added]


Maybe the simplest thing to do is to write a method similar to getAdd2CartBlockWidget in a class decorating ListItem and call it from an appropriate twig, but then where can I define getDefaultAction() or something similar? The getAdd2CartBlockWidget() looks like
Code:
protected function getAdd2CartBlockWidget() { $widget = null; ... $widget = $this->getWidget( [ 'style' => 'add-to-cart product-add2cart productid-' . $this ->getProduct()->getProductId(), 'label' => 'Add to cart', ], 'XLite\View\Button\Simple' ); } return $widget;
and it is some jquery scripts that deals with the action of button. And in the javascript, I haven't seen functions that looks like doActionAddtoCart() that is in the controller.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote