Skip to content

Commit

Permalink
Merge branch 'master' into feature/PLUG-3755
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinverschoor committed Aug 30, 2024
2 parents d6a6732 + ece09fa commit 22afa36
Show file tree
Hide file tree
Showing 50 changed files with 3,005 additions and 58 deletions.
48 changes: 48 additions & 0 deletions Block/Adminhtml/Render/CacheButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Paynl\Payment\Block\Adminhtml\Render;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\UrlInterface;

class CacheButton extends Field
{
/**
* @var UrlInterface
*/
protected $urlInterface;

/**
* constructor.
* @param Context $context
* @param UrlInterface $urlInterface
*/
public function __construct(
Context $context,
UrlInterface $urlInterface
) {
$this->urlInterface = $urlInterface;
parent::__construct($context);
}

/**
* Render block: extension version
*
* @param AbstractElement $element
*
* @return string
*/
public function render(AbstractElement $element)
{
$currentUrl = $this->urlInterface->getCurrentUrl();
$payUrl = str_replace("system_config/edit/section/paynl_paymentmethods", "cache", $currentUrl);

$text = __('When updating this setting, please flush Magento\'s cache afterwards ') . ' <a href="' . $payUrl . '">' . __('here') . '</a>.';
$html = '<tr id="row_' . $element->getHtmlId() . '" class="PaynlCacheButton">';
$html .= '<td></td><td class="value">' . $text . '</td>';
$html .= '</tr>';
return $html;
}
}
24 changes: 24 additions & 0 deletions Block/Checkout/FastCheckout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Paynl\Payment\Block\Checkout;

use Magento\Catalog\Block\Product\Context;
use Magento\Catalog\Block\Product\ProductList\Item\Block;
use Magento\Framework\View\Page\Config;

class FastCheckout extends Block
{
/**
* @param Context $context
* @param Config $page
* @param array $data
*/
public function __construct(
Context $context,
Config $page,
array $data = []
) {
$page->addPageAsset('Paynl_Payment::css/payFastCheckout.css');
parent::__construct($context, $data);
}
}
104 changes: 104 additions & 0 deletions Block/Page/FastCheckoutFallback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Paynl\Payment\Block\Page;

use Magento\Checkout\Model\Cart;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\App\Request\Http as Request;
use Magento\Framework\App\Response\Http as Response;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Page\Config;

class FastCheckoutFallback extends \Magento\Framework\View\Element\Template
{
/**
* @var Request
*/
protected $request;

/**
* @var Response
*/
private $response;

/**
* @var Cart
*/
private $cart;

/**
* @var CacheInterface
*/
public $cache;

/**
* @var ManagerInterface
*/
public $messageManager;

/**
* @param Context $context
* @param Request $request
* @param Response $response
* @param Cart $cart
* @param CacheInterface $cache
* @param Config $page
* @param ManagerInterface $messageManager
* @param array $data
*/
public function __construct(
Context $context,
Request $request,
Response $response,
Cart $cart,
CacheInterface $cache,
Config $page,
ManagerInterface $messageManager,
array $data = []
) {
$page->addPageAsset('Paynl_Payment::css/payFastCheckout.css');
parent::__construct($context, $data);
$this->cart = $cart;
$this->request = $request;
$this->response = $response;
$this->cache = $cache;
$this->messageManager = $messageManager;
}

/**
* Initialize data and prepare it for output
*
* @return string
*/
protected function _beforeToHtml() // phpcs:ignore
{
return parent::_beforeToHtml();
}

/**
* @return array
*/
public function getShippingMethods()
{
$cacheName = 'shipping_methods_' . $this->cart->getQuote()->getId();
$shippingMethodJson = $this->cache->load($cacheName);

if (empty($shippingMethodJson)) {
$this->messageManager->addNoticeMessage(__('Unfortunately fast checkout is currently not possible.'));
$this->response->setRedirect('/checkout/cart');
} else {
return json_decode($shippingMethodJson);
}
}

/**
* @param string $param
* @return string|null
*/
public function getParam($param)
{
$params = $this->request->getParams();
return (isset($params[$param])) ? $params[$param] : null;
}
}
Loading

0 comments on commit 22afa36

Please sign in to comment.