Skip to content

Commit

Permalink
pushed from bitbucket
Browse files Browse the repository at this point in the history
  • Loading branch information
1jenkins committed Feb 3, 2021
1 parent e414fd3 commit 3f92505
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 8 deletions.
59 changes: 57 additions & 2 deletions Block/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ class Main extends \Magento\Framework\View\Element\Template
protected $transactionBuilder;
protected $customerSession;
protected $toolkit_url;
protected $_productRepositoryFactory;

public function __construct(
Context $context,
Session $checkoutSession,
OrderFactory $orderFactory,
\Magento\Customer\Model\Session $customerSession,
TransactionBuilder $tb,
\Magento\Framework\Message\ManagerInterface $messageManager
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\Catalog\Api\ProductRepositoryInterfaceFactory $productRepositoryFactory
) {
$this->toolkit_url = '';
$this->checkoutSession = $checkoutSession;
Expand All @@ -34,6 +36,7 @@ public function __construct(
$this->customerSession = $customerSession;
$this->transactionBuilder = $tb;
$this->_messageManager = $messageManager;
$this->_productRepositoryFactory = $productRepositoryFactory;

$this->urlBuilder = \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\UrlInterface');
Expand Down Expand Up @@ -82,7 +85,8 @@ protected function _prepareLayout()
'country' => $this->encode_string($billing->getCountryId()),
'zip' => $this->encode_string($billing->getPostcode())
],
'category' => $this->encode_string($order->getPayment()->getMethodInstance()->getCode())
'category' => $this->encode_string($order->getPayment()->getMethodInstance()->getCode()),
'cart' => $this->encode_string($this->getCartItems($order))
];

$order->save();
Expand Down Expand Up @@ -130,6 +134,57 @@ protected function _prepareLayout()
}
}

public function getCartItems($order)
{
try {
$items = $order->getAllVisibleItems();
$cart=[];
foreach ($items as $item) {
$cart[] = $this->buildCartItem($item->getName(), $item->getPriceInclTax(), $item->getData('qty_ordered'), $this->getProductImage($item));//getQtyToShip()
}
$cart = $this->addShippingItem($order, $cart);
return json_encode($cart, JSON_UNESCAPED_SLASHES);
} catch (\Exception $e) {
return '';
}
}

public function addShippingItem($order, $cart)
{
$shipping_amount=$order->getShippingAmount();
if ($shipping_amount>0) {
$cart[]=$this->buildCartItem('shipping', $shipping_amount, 1, '');
}
return $cart;
}

public function getProductImage($item)
{
try {
$product = $this->_productRepositoryFactory->create()
->getById($item->getProductId());
$objectManager =\Magento\Framework\App\ObjectManager::getInstance();
$helperImport = $objectManager->get('\Magento\Catalog\Helper\Image');

return $helperImport->init($product, 'product_page_image_small')
->setImageFile($product->getSmallImage()) // image,small_image,thumbnail
->resize(380)
->getUrl();
} catch (\Exception $e) {
return '';
}
}

public function buildCartItem($name, $amount, $quantity, $image)
{
return [
'name' => $name,
'amount' => $amount,
'quantity' => $quantity,
'image' => $image
];
}

public function getLine2($object)
{
try {
Expand Down
10 changes: 5 additions & 5 deletions Model/RapydPaymentMethodAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ abstract class RapydPaymentMethodAbstract extends \Magento\Payment\Model\Method\
protected $_canOrder = true;
protected $_isGateway = true;
protected $_canUseInternal = false;
protected $categories;

abstract public function getCategory();

Expand All @@ -23,14 +22,15 @@ public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
{
try {
$api = $this->getRapydObject();
if (empty($this->categories)) {
$this->categories = $api->make_request_to_rapyd('get', \Rapyd\Rapydmagento2\lib\RapydConsts::RAPYD_CATEGORIES_PATH);
$instance = \Rapyd\Rapydmagento2\lib\RapydCategories::getInstance();
if (empty($instance->getCategories())) {
$instance->setCategories($api->make_request_to_rapyd('get', \Rapyd\Rapydmagento2\lib\RapydConsts::RAPYD_CATEGORIES_PATH));
}

if (!($this->categories) || (!empty($this->categories['status']) && 'ERROR' == $this->categories['status']['status'])) {
if (!($instance->getCategories()) || (!empty($instance->getCategories()['status']) && 'ERROR' == $instance->getCategories()['status']['status'])) {
return false;
}
foreach ($this->categories as $value) {
foreach ($instance->getCategories() as $value) {
if ($value == $this->getCategory()) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rapyd/rapydmagento2",
"description": "Rapyd Payments Plugin for Magento",
"type": "magento2-module",
"version": "1.0.0",
"version": "1.0.1",
"license": [
"Apache-2.0"
],
Expand Down
31 changes: 31 additions & 0 deletions lib/RapydCategories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Rapyd\Rapydmagento2\lib;

class RapydCategories
{
private static $instance = null;
private $categories;

private function __construct()
{
}

public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new RapydCategories();
}
return self::$instance;
}

public function getCategories()
{
return $this->categories;
}

public function setCategories($categories)
{
$this->categories = $categories;
}
}
3 changes: 3 additions & 0 deletions view/frontend/web/js/rapyd-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ require(['jquery','domReady!'], function ($) {
}

function createInstructions(instructions) {
if(!instructions[0] || !instructions[0]["steps"] || instructions[0]["steps"].length==0){
return;
}
createHeadlineForInstructions();
var ul = document.createElement('ul');
ul.style.marginLeft = "unset";
Expand Down

0 comments on commit 3f92505

Please sign in to comment.