diff --git a/Block/Adminhtml/Order/Create/Shipping/Method/Form.php b/Block/Adminhtml/Order/Create/Shipping/Method/Form.php index 577e892..2e50636 100644 --- a/Block/Adminhtml/Order/Create/Shipping/Method/Form.php +++ b/Block/Adminhtml/Order/Create/Shipping/Method/Form.php @@ -6,7 +6,6 @@ namespace MagePal\CustomShippingRate\Block\Adminhtml\Order\Create\Shipping\Method; - class Form extends \Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\Form { @@ -15,7 +14,8 @@ class Form extends \Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method\F * * @return string */ - public function getActiveCustomShippingRateMethod(){ + public function getActiveCustomShippingRateMethod() + { $rate = $this->getActiveMethodRate(); return $rate && $rate->getCarrier() == \MagePal\CustomShippingRate\Model\Carrier::CODE ? $rate->getMethod() : ''; } @@ -25,20 +25,20 @@ public function getActiveCustomShippingRateMethod(){ * * @return string */ - public function getActiveCustomShippingRatePrice(){ + public function getActiveCustomShippingRatePrice() + { $rate = $this->getActiveMethodRate(); return $this->getActiveCustomShippingRateMethod() && $rate->getPrice() ? $rate->getPrice() * 1 : ''; } - /** * Custom shipping rate * * @return string */ - public function isCustomShippingRateActive(){ + public function isCustomShippingRateActive() + { $rate = $this->getActiveMethodRate(); return $rate && $rate->getCarrier() == \MagePal\CustomShippingRate\Model\Carrier::CODE ? true : false; } - -} \ No newline at end of file +} diff --git a/Block/Adminhtml/System/Config/Form/Composer/Version.php b/Block/Adminhtml/System/Config/Form/Composer/Version.php index e4dc33b..7047aad 100644 --- a/Block/Adminhtml/System/Config/Form/Composer/Version.php +++ b/Block/Adminhtml/System/Config/Form/Composer/Version.php @@ -55,7 +55,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele return parent::render($element); } - /** * Return element html * @@ -68,13 +67,13 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract return 'v' . $this->getVersion(); } - /** * Get Module version number * * @return string */ - public function getVersion(){ + public function getVersion() + { return $this->getComposerVersion($this->getModuleName()); } @@ -101,21 +100,18 @@ public function getComposerVersion($moduleName) $moduleName ); - try{ + try { $directoryRead = $this->readFactory->create($path); $composerJsonData = $directoryRead->readFile('composer.json'); - if($composerJsonData){ + if ($composerJsonData) { $data = json_decode($composerJsonData); return !empty($data->version) ? $data->version : __('Unknown'); } - - } - catch (\Exception $e){ + } catch (\Exception $e) { // } return 'Unknown'; - } } diff --git a/Block/Adminhtml/System/Config/Form/Field/Link.php b/Block/Adminhtml/System/Config/Form/Field/Link.php index e8cd47f..fcca96d 100644 --- a/Block/Adminhtml/System/Config/Form/Field/Link.php +++ b/Block/Adminhtml/System/Config/Form/Field/Link.php @@ -9,7 +9,6 @@ class Link extends \Magento\Config\Block\System\Config\Form\Field { - /** * @param \Magento\Backend\Block\Template\Context $context * @param array $data @@ -34,7 +33,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele return parent::render($element); } - /** * Return element html * @@ -44,12 +42,10 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele */ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) { - return sprintf('%s', + return sprintf( + '%s', $this->_urlBuilder->getUrl('adminhtml/system_config/edit/section/carriers'), __('Store > Configuration > Shipping Methods > Custom Shipping Rate') ); } - - - } diff --git a/Block/Adminhtml/System/Config/Form/Field/ShippingList.php b/Block/Adminhtml/System/Config/Form/Field/ShippingList.php index dc533f3..0bfc13f 100644 --- a/Block/Adminhtml/System/Config/Form/Field/ShippingList.php +++ b/Block/Adminhtml/System/Config/Form/Field/ShippingList.php @@ -7,6 +7,7 @@ namespace MagePal\CustomShippingRate\Block\Adminhtml\System\Config\Form\Field; use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; + /** * Class Locations Backend system config array field renderer */ diff --git a/Block/Adminhtml/System/Config/Form/Module/Version.php b/Block/Adminhtml/System/Config/Form/Module/Version.php index 3b2609f..e532e66 100644 --- a/Block/Adminhtml/System/Config/Form/Module/Version.php +++ b/Block/Adminhtml/System/Config/Form/Module/Version.php @@ -41,7 +41,6 @@ public function render(\Magento\Framework\Data\Form\Element\AbstractElement $ele return parent::render($element); } - /** * Return element html * @@ -54,13 +53,13 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract return 'v' . $this->getVersion(); } - /** * Get Module version number * * @return string */ - public function getVersion(){ + public function getVersion() + { $moduleInfo = $this->_moduleList->getOne($this->getModuleName()); return $moduleInfo['setup_version']; } diff --git a/Helper/Data.php b/Helper/Data.php index 3bbf9f8..8c8b2f6 100644 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -13,25 +13,22 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper { - - public function getShippingType(){ + public function getShippingType() + { $arrayValues = []; $configData = $this->getConfigData('shipping_type'); if (is_string($configData) && !empty($configData) && $configData !== '[]') { - if($this->isJson($configData)){ + if ($this->isJson($configData)) { $arrayValues = json_decode($configData, true); - } - else{ + } else { $arrayValues = array_values(unserialize($configData)); } - } return (array)$arrayValues; } - /** * @return bool */ @@ -40,7 +37,6 @@ public function isEnabled() return (bool)$this->getConfigData('active'); } - /** * Retrieve information from carrier configuration * @@ -68,10 +64,9 @@ public function getConfigData($field) * @param string $string * @return bool */ - public function isJson($string) { + public function isJson($string) + { json_decode($string); return (json_last_error() == JSON_ERROR_NONE); } - - -} \ No newline at end of file +} diff --git a/Model/Carrier.php b/Model/Carrier.php index e92e557..ce6c6f3 100644 --- a/Model/Carrier.php +++ b/Model/Carrier.php @@ -6,10 +6,8 @@ namespace MagePal\CustomShippingRate\Model; - -use Magento\Shipping\Model\Carrier\AbstractCarrier; use Magento\Quote\Model\Quote\Address\RateRequest; - +use Magento\Shipping\Model\Carrier\AbstractCarrier; class Carrier extends AbstractCarrier implements \Magento\Shipping\Model\Carrier\CarrierInterface { @@ -55,7 +53,6 @@ class Carrier extends AbstractCarrier implements \Magento\Shipping\Model\Carrier */ protected $_customShippingRateHelper; - /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory $rateErrorFactory @@ -89,7 +86,6 @@ public function __construct( $this->_customShippingRateHelper = $customShippingRateHelper; } - /** * Collect and get rates * @@ -104,8 +100,7 @@ public function collectRates(RateRequest $request) return $result; } - - foreach($this->_customShippingRateHelper->getShippingType() as $shippingType){ + foreach ($this->_customShippingRateHelper->getShippingType() as $shippingType) { $rate = $this->_rateMethodFactory->create(); $rate->setCarrier($this->_code); $rate->setCarrierTitle($this->getConfigData('title')); @@ -120,21 +115,18 @@ public function collectRates(RateRequest $request) return $result; } - /** - * Get allowed shipping methods - * - * @return array - */ + /** + * Get allowed shipping methods + * + * @return array + */ public function getAllowedMethods() { return [$this->getCarrierCode() => __($this->getConfigData('name'))]; } - public function isTrackingAvailable() { return false; } - - } diff --git a/Plugin/Quote/Address/Total/ShippingPlugin.php b/Plugin/Quote/Address/Total/ShippingPlugin.php index 61bf638..2288d07 100644 --- a/Plugin/Quote/Address/Total/ShippingPlugin.php +++ b/Plugin/Quote/Address/Total/ShippingPlugin.php @@ -6,7 +6,6 @@ namespace MagePal\CustomShippingRate\Plugin\Quote\Address\Total; - class ShippingPlugin { @@ -20,7 +19,6 @@ class ShippingPlugin */ protected $_quote; - /** * @param \MagePal\CustomShippingRate\Helper\Data $customShippingRateHelper */ @@ -44,11 +42,10 @@ public function aroundCollect( \Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total - ){ - + ) { $returnValue = $proceed($quote, $shippingAssignment, $total); - if(!$this->_customShippingRateHelper->isEnabled()){ + if (!$this->_customShippingRateHelper->isEnabled()) { return $returnValue; } @@ -60,7 +57,7 @@ public function aroundCollect( if (strpos($method, \MagePal\CustomShippingRate\Model\Carrier::CODE) !== false) { $customOption = $this->getCustomShippingJsonToArray($method); - if($customOption && strpos($method, $customOption['code']) !== false){ + if ($customOption && strpos($method, $customOption['code']) !== false) { foreach ($address->getAllShippingRates() as $rate) { if ($rate->getCode() == $customOption['code']) { $cost = $customOption['rate']; @@ -79,7 +76,6 @@ public function aroundCollect( } } } - } return $returnValue; @@ -99,18 +95,16 @@ private function getCustomShippingJsonToArray($json) $jsonToArray = (array)json_decode($json, true); - if(!$json || count($jsonToArray) != 3){ + if (!$json || count($jsonToArray) != 3) { $json = $this->getQuote()->getCustomShippingRateJson(); - if($json){ + if ($json) { $jsonToArray = (array)json_decode($json, true); } - } - - if(is_array($jsonToArray) && count($jsonToArray) == 3){ - foreach($jsonToArray as $key => $value){ + if (is_array($jsonToArray) && count($jsonToArray) == 3) { + foreach ($jsonToArray as $key => $value) { $customOption[$key] = $value; } @@ -119,7 +113,6 @@ private function getCustomShippingJsonToArray($json) } return false; - } /** @@ -139,5 +132,4 @@ public function getQuote() { return $this->_quote; } - -} \ No newline at end of file +} diff --git a/composer.json b/composer.json index 3ec5f1d..683717e 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "custom shipping" ], "type": "magento2-module", - "version": "1.3.1", + "version": "1.3.2", "license": [ "MagePal License" ], diff --git a/view/adminhtml/templates/order/create/shipping/method/form.phtml b/view/adminhtml/templates/order/create/shipping/method/form.phtml index 03c3de6..fa3eb0d 100644 --- a/view/adminhtml/templates/order/create/shipping/method/form.phtml +++ b/view/adminhtml/templates/order/create/shipping/method/form.phtml @@ -13,12 +13,16 @@