Skip to content

Commit

Permalink
Merge pull request #72 from Paazl/1.9.0
Browse files Browse the repository at this point in the history
1.9.0
  • Loading branch information
Marvin-Magmodules authored Sep 28, 2021
2 parents cbfc719 + fdbc8eb commit dcd4dc3
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 100 deletions.
12 changes: 12 additions & 0 deletions Model/Checkout/WidgetConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,22 @@ public function getConfig()

$numberOfProcessingDays = self::DEFAULT_NUMBER_OF_PROCESSING_DAYS;
$goods = [];
$widthAttribute = $this->scopeConfig->getProductAttributeWidth();
$heightAttribute = $this->scopeConfig->getProductAttributeHeight();
$lengthAttribute = $this->scopeConfig->getProductAttributeLength();
$useDimensions = $widthAttribute && $lengthAttribute && $heightAttribute;
foreach ($this->getQuote()->getAllVisibleItems() as $item) {
$goodsItem = [
"quantity" => (int)$item->getQty(),
"weight" => doubleval($item->getWeight()),
"price" => $this->itemHandler->getPriceValue($item)
];
if ($useDimensions) {
$product = $this->productRepository->getById($item->getProduct()->getId());
$goodsItem["length"] = $product->getData($lengthAttribute);
$goodsItem["width"] = $product->getData($widthAttribute);
$goodsItem["height"] = $product->getData($heightAttribute);
}

if (($itemNumberOfProcessingDays = $this->getProductNumberOfProcessingDays($item))
&& $itemNumberOfProcessingDays > $numberOfProcessingDays) {
Expand Down Expand Up @@ -190,6 +200,8 @@ public function getConfig()
}
if ($this->scopeConfig->getTotalPrice() == 'grand_total') {
$config['shipmentParameters']['totalPrice'] = (float)$this->getQuote()->getGrandTotal();
} elseif ($this->scopeConfig->getTotalPrice() == 'subtotal_excl_discount') {
$config['shipmentParameters']['totalPrice'] = (float)$this->getQuote()->getSubtotal();
}

$config = array_merge($config, $this->languageProvider->getConfig());
Expand Down
1 change: 1 addition & 0 deletions Model/System/Config/Source/TotalPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function toOptionArray()
if (!$this->options) {
$this->options = [
['value' => 'subtotal_incl_discount', 'label' => __('Subtotal including DISCOUNT')],
['value' => 'subtotal_excl_discount', 'label' => __('Subtotal excluding DISCOUNT')],
['value' => 'grand_total', 'label' => __('Grand total')]
];
}
Expand Down
21 changes: 12 additions & 9 deletions Plugin/Carrier/Infotext.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Infotext
* Infotext constructor.
*
* @param ShippingMethodExtensionFactory $extensionFactory
* @param Config $scopeConfig
* @param Config $scopeConfig
*/
public function __construct(
ShippingMethodExtensionFactory $extensionFactory,
Expand All @@ -54,15 +54,18 @@ public function __construct(
public function afterModelToDataObject(ShippingMethodConverter $subject, ShippingMethodInterface $result)
{
$carrierCode = $result->getCarrierCode();
$infotext = $this->scopeConfig->getValue(
'carriers/' . $carrierCode . '/infotext'
);
$extensibleAttribute = ($result->getExtensionAttributes())
? $result->getExtensionAttributes()
: $this->extensionFactory->create();
if ($carrierCode == 'paazlshipping') {
$infotext = $this->scopeConfig->getValue(
'carriers/' . $carrierCode . '/infotext'
);
$extensibleAttribute = ($result->getExtensionAttributes())
? $result->getExtensionAttributes()
: $this->extensionFactory->create();

$extensibleAttribute->setInfotext($infotext);
$result->setExtensionAttributes($extensibleAttribute);
}

$extensibleAttribute->setInfotext($infotext);
$result->setExtensionAttributes($extensibleAttribute);
return $result;
}
}
84 changes: 0 additions & 84 deletions Plugin/Quote/AfterAddProduct.php

This file was deleted.

67 changes: 67 additions & 0 deletions Plugin/Quote/BeforeQuoteSave.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Copyright © 2019 Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Paazl\CheckoutWidget\Plugin\Quote;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\QuoteRepository;
use Paazl\CheckoutWidget\Model\Config;

/**
* Class BeforeQuoteSave
* Plugin for quote repository
*/
class BeforeQuoteSave
{

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

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

/**
* @param QuoteRepository $subject
* @param CartInterface $quote
*
* @return CartInterface[]
*/
public function beforeSave(
QuoteRepository $subject,
CartInterface $quote
) {
$shippingAddress = $quote->getShippingAddress();
if (!$shippingAddress->getCountryId() && $this->config->isEnabled()) {
$origin = $this->scopeConfig->getValue(self::ORIGIN);
$shippingAddress = $quote->getShippingAddress();
$billingAddress = $quote->getBillingAddress();
$billingAddress->setCountryId($origin);
$shippingAddress->setCountryId($origin);
$quote->setShippingAddress($shippingAddress);
$quote->setBillingAddress($billingAddress);
}
return [$quote];
}
}
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.8.0",
"version": "1.9.0",
"keywords": [
"Paazl",
"Magento 2",
Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,14 @@
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[If you use the third 'street' field as a separate house-number-addition field, enable this option.]]></comment>
</field>
<field id="infotext" translate="label comment" type="textarea" sortOrder="46" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Infotext</label>
<depends>
<field id="active">1</field>
</depends>
<comment>Use this to show some info on checkout shipping method.</comment>
</field>
<field id="reference_prefix" translate="label comment" type="text" sortOrder="47" showInDefault="1"
showInWebsite="1" showInStore="1">
<label>Order reference prefix</label>
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.8.0</version>
<version>v1.9.0</version>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
Expand Down
6 changes: 3 additions & 3 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
sortOrder="70"/>
</type>

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

<type name="Magento\Tax\Model\Config">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ define(
return;
}

var methods = res.extension_attributes && res.extension_attributes.shipping_methods || [];
var methods = res.totals.extension_attributes
&& res.totals.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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
attr="'aria-labelledby': 'label_method_' + method.method_code + '_' + method.carrier_code + ' ' + 'label_carrier_' + method.method_code + '_' + method.carrier_code" />
<!-- /ko -->
<tr class="row info">
<td class="col" colspan="4" style="border-top:none;padding:0;"><div class="infoblock" attr="'id': 'infotext_' + method.method_code + '_' + method.carrier_code" if="method.extension_attributes" style="display:block" text="method.extension_attributes.infotext"></div></td>
<td class="col" colspan="4" style="border-top:none;padding:0;">
<div class="infoblock" attr="'id': 'infotext_' + method.method_code + '_' + method.carrier_code" if="method.extension_attributes" style="display:block" text="method.extension_attributes.infotext"></div>
</td>
</tr>
<tr class="row info" data-bind="visible: $parent.canShowPaazlWidget() == 'paazlshipping'">
<td class="col" colspan="4" style="border-top:none;padding:0;"><div attr="'id': 'widget_' + method.method_code + '_' + method.carrier_code"></div></td>
Expand Down

0 comments on commit dcd4dc3

Please sign in to comment.