Skip to content

Commit

Permalink
Merge pull request #84 from Paazl/release/1.9.3
Browse files Browse the repository at this point in the history
Release/1.9.3
  • Loading branch information
Marvin-Magmodules authored Nov 29, 2021
2 parents e0f64da + 91960da commit 41b6288
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 53 deletions.
1 change: 1 addition & 0 deletions Model/Api/PaazlApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function addOrder(array $orderData, bool $modify = false)
$this->generalHelper->addTolog('AddOrder response body: ', $body);
} else {
$this->generalHelper->addTolog('ModifyOrder request: ', $orderData);
unset($orderData['products']);
$httpClient->put($url, json_encode($orderData));
$body = $httpClient->getBody();
$status = $httpClient->getStatus();
Expand Down
32 changes: 32 additions & 0 deletions Model/ResourceModel/QuoteAddress/Resource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Paazl\CheckoutWidget\Model\ResourceModel\QuoteAddress;

use Magento\Quote\Model\ResourceModel\Quote\Address;

/**
* Class Resource
*/
class Resource extends Address
{
/**
* @param int $quoteId
* @return string
*/
public function getShippingMethodByQuoteId(int $quoteId)
{
$connection = $this->getConnection();
$select = $connection->select()->from(
$this->getTable('quote_address'),
'shipping_method'
)->where('quote_id = :quote_id')
->where('address_type = ?', 'shipping');
$bind = [':quote_id' => $quoteId];
return $connection->fetchOne($select, $bind);
}
}
23 changes: 0 additions & 23 deletions Model/TokenRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,29 +161,6 @@ public function retrieveByOrder(OrderInterface $order)
return $this->token;
}

/**
* Refreshes API token in quote reference
*
* @param QuoteReferenceInterface $reference
* @param string $token
* @throws LocalizedException
*/
protected function refreshQuoteReferenceApiToken(QuoteReferenceInterface $reference, $token)
{
try {
$gmtNow = $this->timezone->date(null, null, false);
// @codingStandardsIgnoreLine
$gmtNow->add(new \DateInterval('P30D'));
$reference
->setToken($token)
->setTokenExpiresAt($this->dateTime->gmtDate(null, $gmtNow));

$this->quoteReferenceRepository->save($reference);
} catch (\Exception $exception) {
throw new LocalizedException(__($exception->getMessage()), $exception);
}
}

/**
* Retrieves Quote Reference
*
Expand Down
38 changes: 14 additions & 24 deletions Plugin/Tax/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@

namespace Paazl\CheckoutWidget\Plugin\Tax;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Tax\Model\Config as TaxConfigModel;
use Paazl\CheckoutWidget\Helper\Order as OrderHelper;
use Paazl\CheckoutWidget\Model\Config as PaazlConfig;
use Magento\Quote\Api\Data\ShippingMethodInterface;
use Magento\Checkout\Model\Session;
use Magento\Quote\Api\CartRepositoryInterface;
use Paazl\CheckoutWidget\Model\ResourceModel\QuoteAddress\Resource as QuoteAddressResource;

/**
* Tax Config Plugin
Expand All @@ -32,32 +30,30 @@ class Config
* @var Session
*/
private $session;

/**
* @var CartRepositoryInterface
* @var QuoteAddressResource
*/
private $cartRepository;
private $quoteAddressResource;

/**
* Config constructor.
*
* @param OrderHelper $orderHelper
* @param PaazlConfig $paazlConfig
* @param ShippingMethodInterface $shippingMethod
* @param Session $session
* @param CartRepositoryInterface $cartRepository
* @param QuoteAddressResource $quoteAddressResource
*/
public function __construct(
OrderHelper $orderHelper,
PaazlConfig $paazlConfig,
ShippingMethodInterface $shippingMethod,
Session $session,
CartRepositoryInterface $cartRepository
QuoteAddressResource $quoteAddressResource
) {
$this->orderHelper = $orderHelper;
$this->paazlConfig = $paazlConfig;
$this->shippingMethod = $shippingMethod;
$this->session = $session;
$this->cartRepository = $cartRepository;
$this->quoteAddressResource = $quoteAddressResource;
}

/**
Expand All @@ -72,19 +68,13 @@ public function afterShippingPriceIncludesTax(
bool $result,
$store = null
) {
try {
$cartId = $this->session->getQuoteId();
//we can't use Magento\Checkout\Model\Session::getQuote() because of infinity loop on place order
$quote = $this->cartRepository->getActive($cartId);
$shippingMethod = $quote->getShippingAddress()->getShippingMethod();
if ($shippingMethod
&& $this->orderHelper->isPaazlShippingMethod($shippingMethod)
&& $this->paazlConfig->isPriceIncludesTax($store)
) {
return true;
}
} catch (NoSuchEntityException $e) {
return $result;
$cartId = $this->session->getQuoteId();
$shippingMethod = $this->quoteAddressResource->getShippingMethodByQuoteId((int)$cartId);
if ($shippingMethod
&& $this->orderHelper->isPaazlShippingMethod($shippingMethod)
&& $this->paazlConfig->isPriceIncludesTax($store)
) {
return true;
}

return $result;
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": "paazl/magento2-checkout-widget",
"description": "Paazl checkoutWidget for Magento 2",
"type": "magento2-module",
"version": "1.9.2",
"version": "1.9.3",
"keywords": [
"Paazl",
"Magento 2",
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<default>
<carriers>
<paazlshipping>
<version>v1.9.2</version>
<version>v1.9.3</version>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ define(
|| widgetConfig.prototype.getMethodCode() !== shippingMethod.method_code) {
return;
}

var methods = res.totals.extension_attributes
&& res.totals.extension_attributes.shipping_methods
|| [];
var methods = [];
if ((typeof res.totals !== 'undefined')
&& (typeof res.totals.extension_attributes !== 'undefined')) {
methods = res.totals.extension_attributes || [];
} else if (typeof res.extension_attributes !== 'undefined') {
methods = res.extension_attributes.shipping_methods || [];
}
var found = _.find(methods, function (m) {
return m.carrier_code === shippingMethod.carrier_code
&& m.method_code === shippingMethod.method_code;
Expand Down

0 comments on commit 41b6288

Please sign in to comment.