b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / app / code / WeSupply / Toolbox / Block /
Filename/home/dev2.destoffenstraat.com/app/code/WeSupply/Toolbox/Block/Orders.php
Size4.23 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified17-May-2021 07:14
Last accessed22-Aug-2025 01:36
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

namespace WeSupply\Toolbox\Block;

use Magento\Framework\Session\SessionManagerInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\View\Element\Template;
use WeSupply\Toolbox\Helper\Data as Helper;
use WeSupply\Toolbox\Api\WeSupplyApiInterface;

class Orders extends Template
{
/**
* @var SessionManagerInterface
*/
protected $_session;

/**
* @var Helper
*/
protected $_helper;

/**
* @var WeSupplyApiInterface
*/
protected $weSupplyApi;

/**
* @var string
*/
private $searchByKey;

/**
* @var string
*/
private $searchByVal;

/**
* Orders constructor.
* @param Context $context
* @param Helper $helper
* @param SessionManagerInterface $session
* @param WeSupplyApiInterface $weSupplyApi
*/
public function __construct(
Context $context,
Helper $helper,
SessionManagerInterface $session,
WeSupplyApiInterface $weSupplyApi
)
{
$this->_isScopePrivate = true;

$this->_helper = $helper;
$this->_session = $session;
$this->weSupplyApi = $weSupplyApi;

parent::__construct($context);
}

/**
* @return string
*/
public function getIframeUrl()
{
$this->setSearchParams($this->getAuthSearchBy());
if (is_null($this->searchByKey) || is_null($this->searchByVal)) {
return $this->getIframeUri() . '?platformType=' . $this->_helper->getPlatform();
}

if ($this->isFirstLoginAttempt()) {
return $this->buildAuthUrl();
}

return $this->buildOrdersViewUrl();
}

/**
* @return string
*/
private function getIframeUri()
{
if ($this->_session->getSessionAliasDomain()) {
return 'https://' . trim($this->_session->getSessionAliasDomain(), '/') . '/';
}

return $this->_helper->getWesupplyFullDomain();
}

/**
* @return bool
*/
private function isFirstLoginAttempt()
{
if ($this->_session->getFirstAttempt()) {
$this->_session->unsFirstAttempt();

return true;
}

return false;
}

/**
* @return string
*/
private function getAuthToken()
{
return $this->_session->getSessionAuthToken();
}

/**
* @return array
*/
private function getAuthSearchBy()
{
return $this->_session->getSessionAuthSearchBy();
}

/**
* @param $auth
*/
private function setSearchParams($auth)
{
reset($auth);
// always set only the first key/value pair
$this->searchByKey = key($auth);
$this->searchByVal = !is_null($this->searchByKey) ? $auth[$this->searchByKey] : null;
}

/**
* @return string
*/
private function buildAuthUrl()
{
if ($this->searchByKey == 'embedded-em') {
return $this->getIframeUri() .
'?token=' . $this->getAuthToken() . '&' . $this->searchByKey . '=' . $this->searchByVal . '&platformType=' . $this->_helper->getPlatform();
}

return $this->grabWeSupplyOrderView();
}

/**
* @return string
*/
private function buildOrdersViewUrl()
{
if ($this->searchByKey == 'embedded-em') {
return $this->getIframeUri() .
'account/orders?platformType=' . $this->_helper->getPlatform();
}

return $this->grabWeSupplyOrderView();
}

/**
* @return string
*/
private function grabWeSupplyOrderView()
{
$this->setApiCredentials();
if ($orderUrlArr = $this->weSupplyApi->weSupplyInterogation($this->searchByVal)) {
return reset($orderUrlArr) . '&platformType=' . $this->_helper->getPlatform();
}

return $this->getIframeUri() . '?platformType=' . $this->_helper->getPlatform();
}

/**
* @return void
*/
private function setApiCredentials()
{
$this->weSupplyApi->setApiPath($this->_helper->getWesupplyApiFullDomain());
$this->weSupplyApi->setApiClientId($this->_helper->getWeSupplyApiClientId());
$this->weSupplyApi->setApiClientSecret($this->_helper->getWeSupplyApiClientSecret());
}
}