Skip to content

Commit

Permalink
Merge pull request #9 from karliuka/phpcs
Browse files Browse the repository at this point in the history
Phpcs
  • Loading branch information
karliuka authored May 19, 2019
2 parents 2a83bdb + 1d84d2b commit f78490f
Show file tree
Hide file tree
Showing 16 changed files with 322 additions and 290 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.directory
/.DS_Store
/*.kate-swp
150 changes: 91 additions & 59 deletions Block/Sales/Email/Shipment/Track.php
Original file line number Diff line number Diff line change
@@ -1,59 +1,91 @@
<?php
/**
* Copyright © 2011-2018 Karliuka Vitalii([email protected])
*
* See COPYING.txt for license details.
*/
namespace Faonni\TrackingLink\Block\Sales\Email\Shipment;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Faonni\TrackingLink\Helper\Data as TrackingLinkHelper;

/**
* Email Track Block
*/
class Track extends Template
{
/**
* Helper
*
* @var \Faonni\TrackingLink\Helper\Data
*/
protected $_helper;

/**
* Initialize Block
*
* @param TrackingLinkHelper $helper
* @param Context $context
* @param array $data
*/
public function __construct(
TrackingLinkHelper $helper,
Context $context,
array $data = []
) {
$this->_helper = $helper;

parent::__construct(
$context,
$data
);
}

/**
* Retrieve Tracking Url
*
* @param \Magento\Shipping\Model\Order\Track $track
* @return string
*/
public function getTrackingUrl($track)
{
$url = $this->_helper->getCarrierUrl(
$track->getCarrierCode(),
$track->getStoreId()
);
return $url ? str_replace('{{number}}', $track->getNumber(), $url) : null;
}
}
<?php
/**
* Copyright © Karliuka Vitalii([email protected])
* See COPYING.txt for license details.
*/
namespace Faonni\TrackingLink\Block\Sales\Email\Shipment;

use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Element\Template\Context;
use Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory as TrackCollectionFactory;
use Faonni\TrackingLink\Helper\Data as TrackingLinkHelper;

/**
* Track block
*/
class Track extends Template
{
/**
* Tracking helper
*
* @var \Faonni\TrackingLink\Helper\Data
*/
protected $helper;

/**
* Track collection
*
* @var \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection
*/
protected $tracksCollection;

/**
* Track collection factory
*
* @var \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\CollectionFactory
*/
protected $trackCollectionFactory;

/**
* Initialize block
*
* @param Context $context
* @param TrackingLinkHelper $helper
* @param TrackCollectionFactory $trackCollectionFactory
* @param array $data
*/
public function __construct(
Context $context,
TrackingLinkHelper $helper,
TrackCollectionFactory $trackCollectionFactory,
array $data = []
) {
$this->helper = $helper;
$this->trackCollectionFactory = $trackCollectionFactory;

parent::__construct(
$context,
$data
);
}

/**
* Retrieve tracking url
*
* @param \Magento\Shipping\Model\Order\Track $track
* @return string
*/
public function getTrackingUrl($track)
{
$url = $this->helper->getCarrierUrl(
$track->getCarrierCode(),
$track->getStoreId()
);
return $url ? str_replace('{{number}}', $track->getNumber(), $url) : null;
}

/**
* Retrieve tracks collection
*
* @param integer $shipmentId
* @return \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection
*/
public function getTracksCollection($shipmentId)
{
if ($this->tracksCollection === null) {
$this->tracksCollection = $this->trackCollectionFactory->create();
$this->tracksCollection->setShipmentFilter($shipmentId);
}
return $this->tracksCollection;
}
}
2 changes: 1 addition & 1 deletion COPYING.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Each Magento source file included in this distribution is licensed under OSL 3.0
Each module source file included in this distribution is licensed under OSL 3.0

http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
Please see LICENSE.txt for the full text of the OSL 3.0 license.
80 changes: 40 additions & 40 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
<?php
/**
* Copyright © 2011-2018 Karliuka Vitalii([email protected])
*
* See COPYING.txt for license details.
*/
namespace Faonni\TrackingLink\Helper;

use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Helper\AbstractHelper;

/**
* TrackingLink Helper
*/
class Data extends AbstractHelper
{
/**
* Retrieve carrier url
*
* @param string $carrierCode
* @param int|Store $store
* @return string|null
*/
public function getCarrierUrl($carrierCode, $store = null)
{
return $this->_getConfig("faonni_tracking/service_url/{$carrierCode}", $store);
}
/**
* Retrieve Store Configuration Data
*
* @param string $path
* @param int|Store $store
* @return string|null
*/
protected function _getConfig($path, $store = null)
{
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $store);
}
}
<?php
/**
* Copyright © Karliuka Vitalii([email protected])
* See COPYING.txt for license details.
*/
namespace Faonni\TrackingLink\Helper;

use Magento\Store\Model\ScopeInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Framework\App\Helper\AbstractHelper;

/**
* TrackingLink Helper
*/
class Data extends AbstractHelper
{
/**
* Retrieve carrier url
*
* @param string $carrierCode
* @param StoreInterface $store
* @return string|null
*/
public function getCarrierUrl($carrierCode, $store = null)
{
return $this->getConfig("faonni_tracking/service_url/{$carrierCode}", $store);
}

/**
* Retrieve Store Configuration Data
*
* @param string $path
* @param StoreInterface $store
* @return string|null
*/
protected function getConfig($path, $store = null)
{
return $this->scopeConfig->getValue($path, ScopeInterface::SCOPE_STORE, $store);
}
}
76 changes: 38 additions & 38 deletions Plugin/Config/Model/Config/Structure/Element/Group.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
/**
* Copyright © 2011-2018 Karliuka Vitalii([email protected])
*
* Copyright © Karliuka Vitalii([email protected])
* See COPYING.txt for license details.
*/
namespace Faonni\TrackingLink\Plugin\Config\Model\Config\Structure\Element;

use Magento\Config\Model\Config\Structure\Element\Group as ElementGroup;
use Magento\Shipping\Model\Config as ShippingConfig;

/**
Expand All @@ -15,87 +15,87 @@ class Group
{
/**
* Shipping Config
*
*
* @var \Magento\Shipping\Model\Config
*/
protected $_shippingConfig;
protected $shippingConfig;

/**
* Initialize Plugin
*
*
* @param ShippingConfig $shippingConfig
*/
public function __construct(
ShippingConfig $shippingConfig
) {
$this->_shippingConfig = $shippingConfig;
$this->shippingConfig = $shippingConfig;
}

/**
* Set Flyweight Data
*
* @param \Magento\Config\Model\Config\Structure\Element\Group $subject
* @param ElementGroup $subject
* @param array $data
* @param string $scope
* @return array
*/
public function beforeSetData($subject, array $data, $scope)
*/
public function beforeSetData(ElementGroup $subject, array $data, $scope)
{
if($data['id'] == 'service_url' && $data['path'] == 'faonni_tracking') {
foreach ($this->_getTrackingCarriers() as $code => $title) {
if (isset($data['children'][$code])) {
continue;
}
$data['children'][$code] = $this->_getFieldData($code, $title);
}
}
if ($data['id'] == 'service_url' && $data['path'] == 'faonni_tracking') {
foreach ($this->getTrackingCarriers() as $code => $title) {
if (isset($data['children'][$code])) {
continue;
}
$data['children'][$code] = $this->getFieldData($code, $title);
}
}
return [$data, $scope];
}

/**
* Retrieve Tracking Carriers
*
* @param string $code
* @param string $title
* @param string $code
* @param string $title
* @return array
*/
protected function _getFieldData($code, $title)
protected function getFieldData($code, $title)
{
return [
'id' => $code,
'type' => 'text',
'showInDefault' => '1',
'showInWebsite' => '1',
'showInStore' => '0',
'label' => (string)__($title),
'path' => 'faonni_tracking/service_url',
'_elementType' => 'field'
];
'id' => $code,
'type' => 'text',
'showInDefault' => '1',
'showInWebsite' => '1',
'showInStore' => '0',
'label' => (string)__($title),
'path' => 'faonni_tracking/service_url',
'_elementType' => 'field'
];
}

/**
* Retrieve Tracking Carriers
*
* @return array
*/
protected function _getTrackingCarriers()
protected function getTrackingCarriers()
{
$carriers = [];
foreach ($this->_getAllCarriers() as $code => $carrier) {
foreach ($this->getAllCarriers() as $code => $carrier) {
if ($carrier->isTrackingAvailable()) {
$carriers[$code] = $carrier->getConfigData('title');
}
}
return $carriers;
}

/**
* Retrieve All System Carriers
*
* @return array
*/
protected function _getAllCarriers()
protected function getAllCarriers()
{
return $this->_shippingConfig->getAllCarriers();
}
return $this->shippingConfig->getAllCarriers();
}
}
Loading

0 comments on commit f78490f

Please sign in to comment.