Skip to content

Commit

Permalink
Merge pull request #65 from Paazl/1.7.0
Browse files Browse the repository at this point in the history
1.7.0
  • Loading branch information
Marvin-Magmodules authored Jun 23, 2021
2 parents 3c64e2f + a7e4b30 commit 4cf54cc
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 5 deletions.
14 changes: 14 additions & 0 deletions Model/Admin/Order/Create/WidgetConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ public function getConfig()
"initialPickupLocations" => $this->getInitialPickupLocations()
];

if ($this->isFreeShippingEnabled() && $shippingAddress->getFreeShipping()) {
$config['shipmentParameters']['startMatrix'] = $this->getFreeShippingMatrixLetter();
}

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

$this->generalHelper->addTolog('config', $config);
Expand Down Expand Up @@ -403,4 +407,14 @@ protected function validateDeliveryMatrixCode(string $value)

return count($matches) === 1;
}

/**
* Check if free shipping enabled in store config
*
* @return bool
*/
protected function isFreeShippingEnabled()
{
return $this->scopeConfig->isFreeShippingEnabled($this->getQuote()->getStoreId());
}
}
22 changes: 22 additions & 0 deletions Model/Checkout/WidgetConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public function getConfig()
"initialPickupLocations" => $this->getInitialPickupLocations()
];

if ($this->isFreeShippingEnabled() && $shippingAddress->getFreeShipping()) {
$config['shipmentParameters']['startMatrix'] = $this->getFreeShippingMatrixLetter();
}

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

$this->generalHelper->addTolog('request', $config);
Expand Down Expand Up @@ -397,6 +401,14 @@ public function isEnabled()
return $this->scopeConfig->isEnabled();
}

/**
* @return mixed
*/
public function getFreeShippingMatrixLetter()
{
return $this->scopeConfig->getFreeShippingMatrixLetter($this->getQuote()->getStoreId());
}

/**
* Gets delivery matrix from product
*
Expand Down Expand Up @@ -433,4 +445,14 @@ protected function validateDeliveryMatrixCode(string $value)

return count($matches) === 1;
}

/**
* Check if free shipping enabled in store config
*
* @return bool
*/
protected function isFreeShippingEnabled()
{
return $this->scopeConfig->isFreeShippingEnabled($this->getQuote()->getStoreId());
}
}
20 changes: 20 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,26 @@ public function isCarrierActive($store = null)
in_array($this->getValue('carriers/' . Paazlshipping::CODE . '/active', $store), [1, 'true']);
}

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

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

/**
* @param null|Store|int|string $store
*
Expand Down
2 changes: 1 addition & 1 deletion Model/System/Config/Source/WidgetTheme.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function toOptionArray()
if (!$this->options) {
$this->options = [
['value' => 'DEFAULT', 'label' => __('Default')],
['value' => 'MINIMAL', 'label' => __('Minimal')],
['value' => 'GREEN', 'label' => __('Green')],
['value' => 'LIGHT-GREEN', 'label' => __('Light Green')],
['value' => 'BROWN', 'label' => __('Brown')],
Expand All @@ -37,7 +38,6 @@ public function toOptionArray()
['value' => 'CUSTOM', 'label' => __('Custom')],
];
}

return $this->options;
}
}
84 changes: 84 additions & 0 deletions Plugin/Quote/AfterAddProduct.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Copyright © 2019 Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Paazl\CheckoutWidget\Plugin\Quote;

use Exception;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Quote\Model\Quote;
use Magento\Quote\Model\Quote as QuoteModel;
use Magento\Catalog\Model\Product;
use Magento\Quote\Model\Quote\Item;
use Magento\Quote\Model\QuoteRepository;
use Paazl\CheckoutWidget\Model\Config;

/**
* Class AfterAddProduct
* Plugin for quote model
*/
class AfterAddProduct
{

const ORIGIN = 'shipping/origin/country_id';
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
/**
* @var QuoteRepository
*/
private $quoteRepository;
/**
* @var Config
*/
private $config;

/**
* Quote constructor.
*
* @param ScopeConfigInterface $scopeConfig
* @param QuoteRepository $quoteRepository
* @param Config $config
*/
public function __construct(
ScopeConfigInterface $scopeConfig,
QuoteRepository $quoteRepository,
Config $config
) {
$this->scopeConfig = $scopeConfig;
$this->quoteRepository = $quoteRepository;
$this->config = $config;
}

/**
* Fire event after item was added to the cart (only after post request)
*
* @param QuoteModel $subject
* @param Item $result
* @param Product $product
*
* @return Item
* @throws Exception
*/
public function afterAddProduct(
QuoteModel $subject,
$result,
Product $product
) {
$shippingAddress = $subject->getShippingAddress();
if (!$shippingAddress->getCountryId() && $this->config->isEnabled()) {
$origin = $this->scopeConfig->getValue(self::ORIGIN);
$shippingAddress = $subject->getShippingAddress();
$billingAddress = $subject->getBillingAddress();
$billingAddress->setCountryId($origin);
$shippingAddress->setCountryId($origin);
$subject->setShippingAddress($shippingAddress);
$subject->setBillingAddress($billingAddress);
$this->quoteRepository->save($subject);
}
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.6.1",
"version": "1.7.0",
"keywords": [
"Paazl",
"Magento 2",
Expand Down
15 changes: 13 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,18 @@
</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="debug" translate="label" type="select" sortOrder="65" showInDefault="1" showInWebsite="1" showInStore="0">
<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>
</field>
<field id="freeshipping_matrix_letter" translate="label comment" type="text" sortOrder="66" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Matrix Letter</label>
<depends>
<field id="freeshipping_enabled">1</field>
</depends>
<comment><![CDATA[API Matrix letter for free shipping]]></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>
<comment>Write API calls to var/log/paazl.log. Not recommended in Paazl's production environment for performance reasons.</comment>
Expand All @@ -268,4 +279,4 @@
</group>
</section>
</system>
</config>
</config>
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.6.1</version>
<version>v1.7.0</version>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
Expand Down
5 changes: 5 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
sortOrder="70"/>
</type>

<type name="Magento\Quote\Model\Quote">
<plugin name="paazlAfterAddProduct"
type="Paazl\CheckoutWidget\Plugin\Quote\AfterAddProduct" sortOrder="1" disabled="false" />
</type>

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

Expand Down

0 comments on commit 4cf54cc

Please sign in to comment.