Skip to content

Commit

Permalink
Merge pull request #99 from Paazl/release/1.14.0
Browse files Browse the repository at this point in the history
Release/1.14.0
  • Loading branch information
Marvin-Magmodules authored Feb 16, 2023
2 parents cbf6c92 + e2b41a0 commit 14fc1c3
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 10 deletions.
26 changes: 19 additions & 7 deletions Cron/SendOrders.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
namespace Paazl\CheckoutWidget\Cron;

use Exception;
use Zend_Db_Expr;
use Magento\Sales\Model\ResourceModel\Order\Collection\Factory;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Paazl\CheckoutWidget\Helper\General as GeneralHelper;
use Paazl\CheckoutWidget\Model\Api\Processor\SendToService;
use Paazl\CheckoutWidget\Model\Config;
use Paazl\CheckoutWidget\Model\ResourceModel\Order\OrderReference;
use Paazl\CheckoutWidget\Helper\General as GeneralHelper;
use Paazl\CheckoutWidget\Model\System\Config\Source\SyncMethod;
use Zend_Db_Expr;

/**
* Class SendOrders
Expand Down Expand Up @@ -42,29 +44,39 @@ class SendOrders
*/
private $generalHelper;

/**
* @var Config
*/
private $config;

/**
* SendOrders constructor.
*
* @param SendToService $sendToService
* @param SendToService $sendToService
* @param CollectionFactory $orderCollectionFactory
* @param GeneralHelper $generalHelper
* @param GeneralHelper $generalHelper
* @param Config $config
*/
public function __construct(
SendToService $sendToService,
CollectionFactory $orderCollectionFactory,
GeneralHelper $generalHelper
GeneralHelper $generalHelper,
Config $config
) {
$this->sendToService = $sendToService;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->generalHelper = $generalHelper;
$this->config = $config;
}

/**
* @return array
*/
public function execute()
{
$messages = [];
if ($this->config->getSyncMethod() != SyncMethod::SYNC_METHOD_CRON) {
return [];
}

$collection = $this->orderCollectionFactory->create();
$collection->getSelect()
Expand All @@ -86,6 +98,6 @@ public function execute()
}
}

return $messages;
return [];
}
}
1 change: 1 addition & 0 deletions Model/Api/Converter/Checkout/ToShippingInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function convert($response)
$info->setPrice(floatval($this->arrayManager->get('shippingOption/rate', $result)));
$info->setOptionTitle($this->arrayManager->get('shippingOption/name', $result));
$info->setPreferredDeliveryDate($this->arrayManager->get('preferredDeliveryDate', $result));
$info->setEstimatedDeliveryRange($this->arrayManager->get('shippingOption/estimatedDeliveryRange', $result));
$info->setCarrierPickupDate($this->arrayManager->get('pickupDate', $result));

if ($info->getType() === DeliveryType::PICKUP) {
Expand Down
2 changes: 1 addition & 1 deletion Model/Api/PaazlApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function fetchCheckoutData($reference)
$httpClient->get($url);
$status = $httpClient->getStatus();
$body = $httpClient->getBody();
$this->generalHelper->addTolog('fetchCheckoutData response status: ', $body);
$this->generalHelper->addTolog('fetchCheckoutData response status: ', $status);
$this->generalHelper->addTolog('fetchCheckoutData response: ', $body);
} catch (Exception $e) {
$this->generalHelper->addTolog('exception', $e->getMessage());
Expand Down
10 changes: 10 additions & 0 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ public function getApiMode($store = null)
return (int)$mode;
}

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

/**
* @param null|Store|int|string $store
*
Expand Down
18 changes: 18 additions & 0 deletions Model/ShippingInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ShippingInfo extends DataObject
public const OPTION_TITLE = 'option_title';
public const ADDRESS = 'address';
public const PREFERRED_DELIVERY_DATE = 'preferred_delivery_date';
public const ESTIMATED_DELIVERY_RANGE = 'estimated_delivery_range';
public const CARRIER_PICKUP_DATE = 'carrier_pickup_date';
/**#@- */

Expand Down Expand Up @@ -240,6 +241,23 @@ public function getPreferredDeliveryDate()
return $this->getData(self::PREFERRED_DELIVERY_DATE);
}

/**
* @param string $value
* @return $this
*/
public function setEstimatedDeliveryRange($value)
{
return $this->setData(self::ESTIMATED_DELIVERY_RANGE, $value);
}

/**
* @return string|null
*/
public function getEstimatedDeliveryRange()
{
return $this->getData(self::ESTIMATED_DELIVERY_RANGE);
}

/**
* @param string $value
* @return $this
Expand Down
41 changes: 41 additions & 0 deletions Model/System/Config/Source/SyncMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Paazl. All rights reserved.
* See COPYING.txt for license details.
*/

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

use Magento\Framework\Data\OptionSourceInterface;

/**
* Class ApiMode
*
* @package Paazl\CheckoutWidget\Model\System\Config\Source
*/
class SyncMethod implements OptionSourceInterface
{

public const SYNC_METHOD_CRON = 0;
public const SYNC_METHOD_MANUAL = 1;

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

/**
* @inheritDoc
*/
public function toOptionArray()
{
if (!$this->options) {
$this->options = [
['value' => self::SYNC_METHOD_CRON, 'label' => __('Cron')],
['value' => self::SYNC_METHOD_MANUAL, 'label' => __('Manual')]
];
}

return $this->options;
}
}
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.13.0",
"version": "1.14.0",
"keywords": [
"Paazl",
"Magento 2",
Expand Down
5 changes: 5 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@
<label>Advanced Settings</label>
<frontend_model>Paazl\CheckoutWidget\Block\Adminhtml\Paazl\Heading</frontend_model>
</field>
<field id="sync_method" translate="label" type="select" sortOrder="61" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sync method</label>
<source_model>Paazl\CheckoutWidget\Model\System\Config\Source\SyncMethod</source_model>
<comment>Choose method to push orders to API.</comment>
</field>
<field id="api_timeout" translate="label" type="text" sortOrder="62" showInDefault="1" showInWebsite="1" showInStore="1">
<label>API Timeout</label>
<comment>Time threshold in seconds after which API is treated as not responding.</comment>
Expand Down
3 changes: 2 additions & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
<default>
<carriers>
<paazlshipping>
<version>v1.13.0</version>
<version>v1.14.0</version>
<active>0</active>
<sallowspecific>0</sallowspecific>
<price>0</price>
<api_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
<api_secret backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
<sync_method>0</sync_method>
<api_timeout>300</api_timeout>
<model>Paazl\CheckoutWidget\Model\Carrier\Paazlshipping</model>
<name>Paazl</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,28 @@ use Paazl\CheckoutWidget\Ui\Component\Order\Listing\Column\Status\Options;
<span class="value"><?= /* @escapeNotVerified */ $preferredDeliveryDate; ?></span>
</span>
<?php endif; ?>
<?php if ($estimatedDeliveryRange = $shippingInfo->getEstimatedDeliveryRange()) : ?>
<span class="estimated-delivery-range date-wrapper">
<span class="label"><?= /* @escapeNotVerified */ __('Earliest Delivery Date'); ?></span>:
<span class="value"><?= /* @escapeNotVerified */ $estimatedDeliveryRange['earliestDate']; ?></span>
</span>
<span class="estimated-delivery-range date-wrapper">
<span class="label"><?= /* @escapeNotVerified */ __('Latest Delivery Date'); ?></span>:
<span class="value"><?= /* @escapeNotVerified */ $estimatedDeliveryRange['latestDate']; ?></span>
</span>
<?php endif; ?>
<?php if ($carrierPickupDate = $shippingInfo->getCarrierPickupDate()) : ?>
<span class="carrier-pickup-date date-wrapper">
<span class="label"><?= /* @escapeNotVerified */ __('Carrier Pickup Date'); ?></span>:
<span class="value"><?= /* @escapeNotVerified */ $carrierPickupDate; ?></span>
</span>
<?php endif; ?>
<?php if (!$preferredDeliveryDate && !$estimatedDeliveryRange && !$carrierPickupDate) : ?>
<span class="no-delivery-date date-wrapper">
<span class="label"><?= /* @escapeNotVerified */ __('Delivery Date'); ?></span>:
<span class="value"><?= /* @escapeNotVerified */ __('No information available'); ?></span>
</span>
<?php endif; ?>
</div>
<?php endif; ?>
</div>
Expand Down

0 comments on commit 14fc1c3

Please sign in to comment.