Skip to content

Commit

Permalink
Merge pull request #68 from Paazl/1.8.0
Browse files Browse the repository at this point in the history
1.8.0
  • Loading branch information
Marvin-Magmodules authored Sep 10, 2021
2 parents 4cf54cc + a212ca1 commit cbfc719
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Model/Checkout/WidgetConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public function getConfig()
if ($this->isFreeShippingEnabled() && $shippingAddress->getFreeShipping()) {
$config['shipmentParameters']['startMatrix'] = $this->getFreeShippingMatrixLetter();
}
if ($this->scopeConfig->getTotalPrice() == 'grand_total') {
$config['shipmentParameters']['totalPrice'] = (float)$this->getQuote()->getGrandTotal();
}

$config = array_merge($config, $this->languageProvider->getConfig());

Expand Down
18 changes: 18 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ public function isFreeShippingEnabled($store = null)
return $this->getValue(self::API_CONFIG_PATH . '/freeshipping_enabled', $store);
}

/**
* @return mixed
*/
public function isPriceIncludesTax($store = null)
{
return $this->getValue(self::API_CONFIG_PATH . '/price_incl_tax', $store);
}

/**
* @param null|Store|int|string $store
*
Expand Down Expand Up @@ -454,6 +462,16 @@ public function getGoogleMapKey($store = null)
return null;
}

/**
* @param null|Store|int|string $store
*
* @return mixed
*/
public function getTotalPrice($store = null)
{
return $this->getValue(self::API_CONFIG_PATH . '/total_price', $store);
}

/**
* @param null|Store|int|string $store
*
Expand Down
36 changes: 36 additions & 0 deletions Model/System/Config/Source/TotalPrice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © 2019 Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Paazl\CheckoutWidget\Model\System\Config\Source;

use Magento\Framework\Option\ArrayInterface;

/**
* Class TotalPrice
*/
class TotalPrice implements ArrayInterface
{

/**
* @var array
*/
public $options;

/**
* @return array
*/
public function toOptionArray()
{
if (!$this->options) {
$this->options = [
['value' => 'subtotal_incl_discount', 'label' => __('Subtotal including DISCOUNT')],
['value' => 'grand_total', 'label' => __('Grand total')]
];
}

return $this->options;
}
}
2 changes: 1 addition & 1 deletion Model/System/Config/Source/WidgetTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function toOptionArray()
['value' => 'DEFAULT', 'label' => __('Default')],
['value' => 'MINIMAL', 'label' => __('Minimal')],
['value' => 'GREEN', 'label' => __('Green')],
['value' => 'LIGHT-GREEN', 'label' => __('Light Green')],
['value' => 'LIGHT_GREEN', 'label' => __('Light Green')],
['value' => 'BROWN', 'label' => __('Brown')],
['value' => 'BLUE', 'label' => __('Blue')],
['value' => 'RED', 'label' => __('Red')],
Expand Down
92 changes: 92 additions & 0 deletions Plugin/Tax/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php
/**
* Copyright © 2019 Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

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;

/**
* Tax Config Plugin
*/
class Config
{
/**
* @var OrderHelper
*/
private $orderHelper;

/**
* @var PaazlConfig
*/
private $paazlConfig;
/**
* @var Session
*/
private $session;
/**
* @var CartRepositoryInterface
*/
private $cartRepository;

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

/**
* @param TaxConfigModel $subject
* @param bool $result
* @param null $store
*
* @return bool
*/
public function afterShippingPriceIncludesTax(
TaxConfigModel $subject,
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;
}

return $result;
}
}
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.7.0",
"version": "1.8.0",
"keywords": [
"Paazl",
"Magento 2",
Expand Down
10 changes: 10 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@
</depends>
<comment><![CDATA[Fill in a valid Google Maps API Key obtained from your <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">Google Account</a>]]></comment>
</field>
<field id="total_price" translate="label" type="select" sortOrder="64" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Total Price</label>
<source_model>Paazl\CheckoutWidget\Model\System\Config\Source\TotalPrice</source_model>
<comment>Select the price which will be used for totalPrice.</comment>
</field>
<field id="freeshipping_enabled" translate="label" type="select" sortOrder="65" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Free Shipping Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand All @@ -262,6 +267,11 @@
</depends>
<comment><![CDATA[API Matrix letter for free shipping]]></comment>
</field>
<field id="price_incl_tax" translate="label" type="select" sortOrder="67" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Price Includes Tax</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>If yes - shipping price will always includes tax regardless Magento settings</comment>
</field>
<field id="debug" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Debug</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
3 changes: 2 additions & 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.7.0</version>
<version>v1.8.0</version>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
Expand All @@ -33,6 +33,7 @@
<widget_initial_pickup_locations>5</widget_initial_pickup_locations>
<insurance_value>0</insurance_value>
<housenumber_default_value>1</housenumber_default_value>
<total_price>subtotal_incl_discount</total_price>
</paazlshipping>
</carriers>
</default>
Expand Down
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
type="Paazl\CheckoutWidget\Plugin\Quote\AfterAddProduct" sortOrder="1" disabled="false" />
</type>

<type name="Magento\Tax\Model\Config">
<plugin name="tax_config_plugin" type="Paazl\CheckoutWidget\Plugin\Tax\Config" disabled="false"/>
</type>

<preference for="Magento\Framework\HTTP\Client\Curl"
type="Paazl\CheckoutWidget\Model\Api\CurlExtra"/>

Expand Down

0 comments on commit cbfc719

Please sign in to comment.