Skip to content

Commit

Permalink
Merge pull request #103 from magmodules/1.4.20
Browse files Browse the repository at this point in the history
1.4.20
  • Loading branch information
Marvin-Magmodules authored Aug 14, 2020
2 parents a1f9ee2 + 5e9baf9 commit 782cea9
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 20 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: php

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4

sudo: false

Expand All @@ -14,4 +14,4 @@ cache:

script:
- composer validate
- find . -name '*.php' | xargs -n 1 -P4 php -l
- find . -name '*.php' | xargs -n 1 -P4 php -l
12 changes: 2 additions & 10 deletions Helper/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Magento\Store\Model\ScopeInterface;
use Magento\Config\Model\ResourceModel\Config as ConfigData;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory as ConfigDataCollectionFactory;
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magmodules\Channable\Logger\ChannableLogger;
use Magento\Framework\App\ProductMetadata;
Expand All @@ -30,14 +29,11 @@ class General extends AbstractHelper

const MODULE_CODE = 'Magmodules_Channable';
const XPATH_EXTENSION_ENABLED = 'magmodules_channable/general/enable';
const XPATH_EXTENSION_VERSION = 'magmodules_channable/general/version';
const XPATH_MARKETPLACE_ENABLE = 'magmodules_channable_marketplace/general/enable';
const XPATH_TOKEN = 'magmodules_channable/general/token';
const XPATH_USE_ROW_ID = 'magmodules_channable/advanced/use_row_id';

/**
* @var ModuleListInterface
*/
private $moduleList;
/**
* @var ProductMetadataInterface
*/
Expand Down Expand Up @@ -88,7 +84,6 @@ class General extends AbstractHelper
public function __construct(
Context $context,
StoreManagerInterface $storeManager,
ModuleListInterface $moduleList,
ProductMetadataInterface $metadata,
ConfigDataCollectionFactory $configDataCollectionFactory,
ConfigData $config,
Expand All @@ -98,7 +93,6 @@ public function __construct(
Unserialize $unserialize
) {
$this->storeManager = $storeManager;
$this->moduleList = $moduleList;
$this->metadata = $metadata;
$this->configDataCollectionFactory = $configDataCollectionFactory;
$this->config = $config;
Expand Down Expand Up @@ -240,9 +234,7 @@ private function isSerialized($value)
*/
public function getExtensionVersion()
{
$moduleInfo = $this->moduleList->getOne(self::MODULE_CODE);

return $moduleInfo['setup_version'];
return $this->getStoreValue(self::XPATH_EXTENSION_VERSION);
}

/**
Expand Down
15 changes: 10 additions & 5 deletions Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,23 @@ public function importOrder($data, $storeId)

$itemCount = $this->addItems->execute($cart, $data, $store, $this->lvb);
$shippingPriceCal = $this->getShippingPrice($cart, $data, $store);
$cart->collectTotals();

$this->checkoutSession->setChannableEnabled(1);
$this->checkoutSession->setChannableShipping($shippingPriceCal);

$shippingMethod = $this->getShippingMethod($cart, $store, $itemCount);
$shippingMethod = $this->getShippingMethod($cart, $store, $itemCount, $shippingPriceCal);
$shippingAddress = $cart->getShippingAddress();
$shippingAddress->setFreeShipping($shippingPriceCal <= 0); // Some carriers also check this flag.

$shippingAddress->setCollectShippingRates(true)
->collectShippingRates()
->setShippingMethod($shippingMethod);

$cart->setPaymentMethod('channable');
$cart->setInventoryProcessed(false);
$cart->getPayment()->importData(['method' => 'channable']);
$cart->collectTotals();
$cart->setTotalsCollectedFlag(false)->collectTotals();
$cart->save();

$cart = $this->cartRepositoryInterface->get($cart->getId());
Expand Down Expand Up @@ -422,12 +425,13 @@ private function getShippingPrice($cart, $data, $store)

/**
* @param CartRepositoryInterface $cart
* @param StoreManagerInterface $store
* @param $itemCount
* @param StoreManagerInterface $store
* @param int $itemCount
* @param float|int $shippingPriceCal
*
* @return mixed|null|string
*/
private function getShippingMethod($cart, $store, $itemCount)
private function getShippingMethod($cart, $store, $itemCount, $shippingPriceCal)
{
$shippingMethod = $this->orderHelper->getShippingMethod($store->getId());
$shippingMethodFallback = $this->orderHelper->getShippingMethodFallback($store->getId());
Expand All @@ -450,6 +454,7 @@ private function getShippingMethod($cart, $store, $itemCount)
$request->setPackageCurrency($store->getCurrentCurrency());
$request->setLimitCarrier('');
$request->setBaseSubtotalInclTax($total);
$request->setFreeShipping($shippingPriceCal <= 0);
$shipping = $this->shippingFactory->create();
$result = $shipping->collectRates($request)->getResult();

Expand Down
39 changes: 39 additions & 0 deletions Plugin/AfterValidateMinimumAmount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magmodules\Channable\Plugin;

use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Quote\Model\Quote;

class AfterValidateMinimumAmount
{
/** @var CheckoutSession $checkoutSession */
private $checkoutSession;

/**
* @param CheckoutSession $checkoutSession
*/
public function __construct(CheckoutSession $checkoutSession)
{
$this->checkoutSession = $checkoutSession;
}

/**
* Disable Minimum Order Amount for Channable orders.
*
* @param Quote $subject
* @param bool $result
*
* @return bool
*/
public function afterValidateMinimumAmount(Quote $subject, bool $result): bool
{
return (bool) $this->checkoutSession->getChannableEnabled() === true ? true : $result;
}
}
2 changes: 1 addition & 1 deletion Service/Product/InventoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function getReservations($sku, $stockId)
->where('stock_id' . ' = ?', $stockId)
->limit(1);
if ($reservationQty = $connection->fetchOne($select)) {
return ($reservationQty * -1);
return max(0, ($reservationQty * -1));
}

return $reservationQty;
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": "magmodules/magento2-channable",
"description": "Channable integration for Magento 2",
"type": "magento2-module",
"version": "1.4.19",
"version": "1.4.20",
"license": "BSD-2-Clause",
"homepage": "https://github.com/magmodules/magento2-channable",
"require": {
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<general>
<enable>0</enable>
<limit>250</limit>
<version>v1.4.20</version>
</general>
<data>
<name_attribute>name</name_attribute>
Expand Down
13 changes: 13 additions & 0 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Quote\Model\Quote">
<plugin name="magmodulesChannableQuote" type="Magmodules\Channable\Plugin\AfterValidateMinimumAmount"/>
</type>
</config>

0 comments on commit 782cea9

Please sign in to comment.