-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
2,493 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
BARQFleet/Shipping/Block/Adminhtml/System/Config/Button.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
namespace BARQFleet\Shipping\Block\Adminhtml\System\Config; | ||
|
||
class Button extends \Magento\Config\Block\System\Config\Form\Field | ||
{ | ||
|
||
|
||
protected function _prepareLayout() | ||
{ | ||
parent::_prepareLayout(); | ||
if (!$this->getTemplate()) { | ||
$this->setTemplate('system/config/button.phtml'); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) | ||
{ | ||
return $this->_toHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
|
||
namespace BARQFleet\Shipping\Controller\Index; | ||
|
||
class Cashondelivery extends \Magento\Framework\App\Action\Action | ||
{ | ||
|
||
protected $resultPageFactory; | ||
protected $jsonHelper; | ||
protected $dataHelper; | ||
protected $checklogger; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param \Magento\Framework\App\Action\Context $context | ||
* @param \Magento\Framework\Json\Helper\Data $jsonHelper | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Framework\View\Result\PageFactory $resultPageFactory, | ||
\BARQFleet\Shipping\Helper\Data $dataHelper, | ||
\Psr\Log\LoggerInterface $checklogger, | ||
\Magento\Framework\Json\Helper\Data $jsonHelper | ||
) { | ||
$this->resultPageFactory = $resultPageFactory; | ||
$this->jsonHelper = $jsonHelper; | ||
$this->dataHelper = $dataHelper; | ||
$this->checklogger = $checklogger; | ||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Execute view action | ||
* | ||
* @return \Magento\Framework\Controller\ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
// try { | ||
|
||
$check = $this->dataHelper->ServiceCheck(); | ||
$this->checklogger->debug($check); | ||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); | ||
$quote = $cart->getQuote(); | ||
$items = $cart->getQuote()->getAllItems(); | ||
$weight = 0; | ||
foreach ($items as $item) { | ||
$weight += ($item->getWeight() * $item->getQty()) ; | ||
} | ||
$weight = $weight/2.205; | ||
|
||
$shippingMethod = $quote->getShippingAddress()->getShippingMethod(); | ||
|
||
if ($shippingMethod=="barq_barq" && $check == "false") { | ||
$result = 1; | ||
$response = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->setData([ | ||
'state' => $result, | ||
'weight' => $weight | ||
]); | ||
} elseif ($shippingMethod=="barq_barq" && $check == "true") { | ||
$result = 0; | ||
$response = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->setData([ | ||
'state' => $result, | ||
'weight' => $weight | ||
]); | ||
} else { | ||
$result = 0; | ||
$response = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON)->setData([ | ||
'state' => $result, | ||
'weight' => $weight | ||
]); | ||
} | ||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
namespace BARQFleet\Shipping\Controller\Index; | ||
|
||
use BARQFleet\Shipping\Helper\Data; | ||
|
||
class Index extends \Magento\Framework\App\Action\Action | ||
{ | ||
|
||
protected $resultPageFactory; | ||
protected $jsonHelper; | ||
protected $logger; | ||
private $helper; | ||
/** | ||
* Constructor | ||
* | ||
* @param \Magento\Framework\App\Action\Context $context | ||
* @param \Magento\Framework\Json\Helper\Data $jsonHelper | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Framework\View\Result\PageFactory $resultPageFactory, | ||
\Psr\Log\LoggerInterface $logger, | ||
\BARQFleet\Shipping\Helper\Data $helper, | ||
\Magento\Framework\Json\Helper\Data $jsonHelper | ||
) { | ||
$this->resultPageFactory = $resultPageFactory; | ||
$this->jsonHelper = $jsonHelper; | ||
$this->helper = $helper; | ||
$this->logger = $logger; | ||
|
||
parent::__construct($context); | ||
} | ||
|
||
/** | ||
* Execute view action | ||
* | ||
* @return \Magento\Framework\Controller\ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
$api_url = $this->helper->getApiURL(); | ||
$auth_key = $this->helper->getAuthroziationKey(); | ||
$api_check =$this->helper->getActiveMethod(); | ||
$this->logger->debug($api_url); | ||
$this->logger->debug($auth_key); | ||
$this->logger->debug($api_check); | ||
$postData = $this->getRequest()->getParam('responsecity'); | ||
if ($api_check == 1) { | ||
$curl = curl_init(); | ||
|
||
curl_setopt_array($curl, [ | ||
CURLOPT_URL => $api_url."/api/v1/merchants/hubs", | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => false, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
CURLOPT_HTTPHEADER => [ | ||
"Authorization:".$auth_key, | ||
"Content-Type: application/json", | ||
"Language: ar" | ||
], | ||
]); | ||
$response_city = curl_exec($curl); | ||
$response = json_decode($response_city); | ||
$err = curl_error($curl); | ||
curl_close($curl); | ||
if ($err) { | ||
// echo "cURL Error #:" . $err; | ||
} else { | ||
foreach ($response as $values) { | ||
if ($postData == $values->city->name) { | ||
$var = $values->city->name; | ||
print_r(json_encode($var)) ; | ||
// return $var; | ||
} | ||
} | ||
} | ||
} else { | ||
print_r(json_encode(0)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<?php | ||
|
||
|
||
namespace BARQFleet\Shipping\Helper; | ||
|
||
use Magento\Framework\App\Helper\AbstractHelper; | ||
use Magento\Framework\Encryption\EncryptorInterface; | ||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Shipping\Model\Config; | ||
use Magento\Framework\App\Helper\Context; | ||
use Magento\Framework\Module\ModuleListInterface; | ||
|
||
class Data extends AbstractHelper | ||
{ | ||
/** | ||
* @var EncryptorInterface | ||
*/ | ||
protected $encryptor; | ||
private $api_url; | ||
private $auth_key; | ||
protected $scopeConfig; | ||
protected $shippingmodelconfig; | ||
protected $moduleList; | ||
|
||
public function __construct( | ||
\Magento\Framework\App\Helper\Context $context, | ||
EncryptorInterface $encryptor, | ||
Config $shippingmodelconfig, | ||
ScopeConfigInterface $scopeConfig, | ||
\Magento\Framework\Module\ModuleListInterface $moduleList | ||
) { | ||
parent::__construct($context); | ||
$this->encryptor = $encryptor; | ||
$this->moduleList = $moduleList; | ||
$this->shippingmodelconfig = $shippingmodelconfig; | ||
$this->scopeConfig = $scopeConfig; | ||
|
||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getActiveMethod() | ||
{ | ||
$config = $this->scopeConfig->getValue( | ||
'carriers/barq/active', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
|
||
return $config; | ||
} | ||
|
||
public function getAuthroziationKey() | ||
{ | ||
$config = $this->scopeConfig->getValue( | ||
'carriers/barq/apiauthenticationkey', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
return $config; | ||
} | ||
|
||
public function getExtensionVersion() | ||
{ | ||
$moduleCode = 'BARQFleet_Shipping'; | ||
$moduleInfo = $this->moduleList->getOne($moduleCode); | ||
return $moduleInfo['setup_version']; | ||
} | ||
|
||
public function getApiURL() | ||
{ | ||
$config = $this->scopeConfig->getValue( | ||
'carriers/barq/apiurl', | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE | ||
); | ||
// $key = $this->encryptor->decrypt($config); | ||
return $config; | ||
} | ||
|
||
|
||
public function serviceCheck() | ||
{ | ||
$api_url = $this->getApiURL(); | ||
$auth_key = $this->getAuthroziationKey(); | ||
|
||
$curl = curl_init(); | ||
curl_setopt_array($curl, [ | ||
CURLOPT_URL => $api_url."/api/v1/merchants/info", | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => false, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
]); | ||
|
||
$response = curl_exec($curl); | ||
$decode_response = json_decode($response); | ||
$err = curl_error($curl); | ||
|
||
curl_close($curl); | ||
|
||
if ($err) { | ||
return "cURL Error #:" . $err; | ||
} else { | ||
$var = $decode_response->is_cod? 'true' : 'false'; | ||
} | ||
return $var; | ||
} | ||
public function cartWeight() | ||
{ | ||
$api_url = $this->getApiURL(); | ||
$auth_key = $this->getAuthroziationKey(); | ||
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); | ||
$cart = $objectManager->get('\Magento\Checkout\Model\Cart'); | ||
$items = $cart->getQuote()->getAllItems(); | ||
|
||
$weight = 0; | ||
foreach ($items as $item) { | ||
$weight += ($item->getWeight() * $item->getQty()) ; | ||
} | ||
$weight = $weight/2.205; | ||
$curl = curl_init(); | ||
|
||
curl_setopt_array($curl, [ | ||
CURLOPT_URL => $api_url."/api/v1/merchants/orders/shipping/".$weight, | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_ENCODING => "", | ||
CURLOPT_MAXREDIRS => 10, | ||
CURLOPT_TIMEOUT => 0, | ||
CURLOPT_FOLLOWLOCATION => false, | ||
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | ||
CURLOPT_CUSTOMREQUEST => "GET", | ||
CURLOPT_HTTPHEADER => [ | ||
"Authorization:".$auth_key, | ||
"Content-Type: application/json" | ||
], | ||
]); | ||
|
||
$response = curl_exec($curl); | ||
$response_weight = curl_exec($curl); | ||
$response = json_decode($response_weight); | ||
$err = curl_error($curl); | ||
curl_close($curl); | ||
|
||
if ($err) { | ||
return "cURL Error #:" . $err; | ||
} else { | ||
$var = $response->price; | ||
} | ||
return $var; | ||
} | ||
} |
Oops, something went wrong.