This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added hscode attribute * added hs_code and country_of_manufacture to extension attributes of orderitems * updated php doc + changed exception class * assigning country_of_manufacture to all existing attribute sets * SEN-166 Servicepoint rates addition * SEN-166: resolve comments in pull request * SEN-166: resolve comments in pull request * SEN-241: resolve calculation issue on missing config value * SEN-241: resolve not taking fixed into account. * SEN-241: remove debug output * SEN-241: modify lenght of varchar field in servicepointrate table * SEN-241: added sen_ prefix in query * SEN-241: Update requestdata to match sendcloud condition naming
- Loading branch information
Showing
28 changed files
with
2,365 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?php | ||
|
||
namespace SendCloud\SendCloud\Block\Adminhtml\Carrier\Servicepointrate; | ||
|
||
use \Magento\Backend\Block\Template\Context; | ||
use \Magento\Backend\Block\Widget\Grid\Extended; | ||
use \Magento\Backend\Helper\Data; | ||
use \SendCloud\SendCloud\Model\Carrier\SendCloud; | ||
use \SendCloud\SendCloud\Model\ResourceModel\Carrier\Servicepointrate\CollectionFactory; | ||
|
||
/** | ||
* Shipping carrier service point rate grid block | ||
* WARNING: This grid is used for export SendCloud Servicepoint rates | ||
*/ | ||
class Grid extends Extended | ||
{ | ||
/** | ||
* Website filter | ||
* | ||
* @var int | ||
*/ | ||
protected $_websiteId; | ||
|
||
/** | ||
* Condition filter | ||
* | ||
* @var string | ||
*/ | ||
protected $_conditionName; | ||
|
||
/** | ||
* @var SendCloud | ||
*/ | ||
protected $_servicepointrate; | ||
|
||
/** | ||
* @var CollectionFactory | ||
*/ | ||
protected $_collectionFactory; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Data $backendHelper | ||
* @param CollectionFactory $collectionFactory | ||
* @param SendCloud $sendcloud | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Data $backendHelper, | ||
CollectionFactory $collectionFactory, | ||
SendCloud $sendcloud, | ||
array $data = [] | ||
) { | ||
$this->_collectionFactory = $collectionFactory; | ||
$this->_servicepointrate = $sendcloud; | ||
parent::__construct($context, $backendHelper, $data); | ||
} | ||
|
||
/** | ||
* Define grid properties | ||
* | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
$this->setId('shippingServicepointrateGrid'); | ||
$this->_exportPageSize = 10000; | ||
} | ||
|
||
/** | ||
* Set current website | ||
* | ||
* @param int $websiteId | ||
* @return $this | ||
*/ | ||
public function setWebsiteId($websiteId) | ||
{ | ||
$this->_websiteId = $this->_storeManager->getWebsite($websiteId)->getId(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve current website id | ||
* | ||
* @return int | ||
*/ | ||
public function getWebsiteId() | ||
{ | ||
if ($this->_websiteId === null) { | ||
$this->_websiteId = $this->_storeManager->getWebsite()->getId(); | ||
} | ||
return $this->_websiteId; | ||
} | ||
|
||
/** | ||
* Set current website | ||
* | ||
* @param string $name | ||
* @return $this | ||
*/ | ||
public function setSenConditionName($name) | ||
{ | ||
$this->_conditionName = $name; | ||
return $this; | ||
} | ||
|
||
/** | ||
* Retrieve current website id | ||
* | ||
* @return int | ||
*/ | ||
public function getSenConditionName() | ||
{ | ||
return $this->_conditionName; | ||
} | ||
|
||
/** | ||
* Prepare shipping table rate collection | ||
* | ||
* @return Grid | ||
*/ | ||
protected function _prepareCollection() | ||
{ | ||
$collection = $this->_collectionFactory->create(); | ||
$collection->setConditionFilter($this->getSenConditionName())->setWebsiteFilter($this->getWebsiteId()); | ||
|
||
$this->setCollection($collection); | ||
|
||
return parent::_prepareCollection(); | ||
} | ||
|
||
|
||
/** | ||
* Prepare table columns | ||
* | ||
* @return Grid | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
protected function _prepareColumns() | ||
{ | ||
$this->addColumn( | ||
'dest_country', | ||
['header' => __('Country'), 'index' => 'dest_country', 'default' => '*'] | ||
); | ||
|
||
$this->addColumn( | ||
'dest_region', | ||
['header' => __('Region/State'), 'index' => 'dest_region', 'default' => '*'] | ||
); | ||
|
||
$this->addColumn( | ||
'dest_zip', | ||
['header' => __('Zip/Postal Code'), 'index' => 'dest_zip', 'default' => '*'] | ||
); | ||
|
||
$label = $this->_servicepointrate->getCode('sen_condition_name_short', $this->getSenConditionName()); | ||
$this->addColumn('condition_value', ['header' => $label, 'index' => 'condition_value']); | ||
|
||
$this->addColumn('price', ['header' => __('Shipping Price'), 'index' => 'price']); | ||
|
||
return parent::_prepareColumns(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
namespace SendCloud\SendCloud\Block\Adminhtml\Form\Field; | ||
|
||
use \Magento\Backend\Block\Widget\Button; | ||
use \Magento\Backend\Model\UrlInterface; | ||
use \Magento\Framework\Data\Form\Element\AbstractElement; | ||
use \Magento\Framework\Data\Form\Element\Factory; | ||
use \Magento\Framework\Data\Form\Element\CollectionFactory; | ||
use \Magento\Framework\Escaper; | ||
|
||
class Export extends AbstractElement | ||
{ | ||
/** | ||
* @var UrlInterface | ||
*/ | ||
protected $_backendUrl; | ||
|
||
/** | ||
* @param Factory $factoryElement | ||
* @param CollectionFactory $factoryCollection | ||
* @param Escaper $escaper | ||
* @param UrlInterface $backendUrl | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Factory $factoryElement, | ||
CollectionFactory $factoryCollection, | ||
Escaper $escaper, | ||
UrlInterface $backendUrl, | ||
array $data = [] | ||
) { | ||
parent::__construct($factoryElement, $factoryCollection, $escaper, $data); | ||
$this->_backendUrl = $backendUrl; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getElementHtml() | ||
{ | ||
/** @var Button $buttonBlock */ | ||
$buttonBlock = $this->getForm()->getParent()->getLayout()->createBlock(Button::class); | ||
|
||
$params = ['website' => $buttonBlock->getRequest()->getParam('website')]; | ||
|
||
$url = $this->_backendUrl->getUrl("sendcloud_exportrates/exportrates/exportrates", $params); | ||
$data = [ | ||
'label' => __('Export SendCloud CSV'), | ||
'onclick' => "setLocation('" . | ||
$url . | ||
"conditionName/' + $('carriers_sendcloud_sen_condition_name').value + '/sendcloud_servicepointrates.csv' )", | ||
'class' => '', | ||
]; | ||
|
||
return $buttonBlock->setData($data)->toHtml(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace SendCloud\SendCloud\Block\Adminhtml\Form\Field; | ||
|
||
use \Magento\Framework\Data\Form\Element\AbstractElement; | ||
|
||
class Import extends AbstractElement | ||
{ | ||
/** | ||
* @return void | ||
*/ | ||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
$this->setType('file'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getElementHtml() | ||
{ | ||
$html = ''; | ||
|
||
$html .= '<input id="time_condition_sendcloud" type="hidden" name="' . $this->getName() . '" value="' . time() . '" />'; | ||
|
||
$html .= <<<EndHTML | ||
<script> | ||
require(['prototype'], function(){ | ||
Event.observe($('carriers_sendcloud_sen_condition_name'), 'change', checkConditionName.bind(this)); | ||
function checkConditionName(event) | ||
{ | ||
var conditionNameElement = Event.element(event); | ||
if (conditionNameElement && conditionNameElement.id) { | ||
$('time_condition_sendcloud').value = '_' + conditionNameElement.value + '/' + Math.random(); | ||
} | ||
} | ||
}); | ||
</script> | ||
EndHTML; | ||
|
||
$html .= parent::getElementHtml(); | ||
|
||
return $html; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
namespace SendCloud\SendCloud\Controller\Adminhtml\Exportrates; | ||
|
||
use Magento\Backend\App\Action\Context; | ||
use Magento\Config\Controller\Adminhtml\System\AbstractConfig; | ||
use Magento\Config\Controller\Adminhtml\System\ConfigSectionChecker; | ||
use Magento\Config\Model\Config\Structure; | ||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\App\ResponseInterface; | ||
use Magento\Framework\App\Response\Http\FileFactory; | ||
use Magento\Framework\Controller\ResultInterface; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use SendCloud\SendCloud\Block\Adminhtml\Carrier\Servicepointrate\Grid; | ||
|
||
class Exportrates extends AbstractConfig | ||
{ | ||
/** | ||
* @var FileFactory | ||
*/ | ||
protected $_fileFactory; | ||
|
||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
protected $_storeManager; | ||
|
||
|
||
/** | ||
* Exportrates constructor. | ||
* @param Context $context | ||
* @param Structure $configStructure | ||
* @param ConfigSectionChecker $sectionChecker | ||
* @param FileFactory $fileFactory | ||
* @param StoreManagerInterface $storeManager | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Structure $configStructure, | ||
ConfigSectionChecker $sectionChecker, | ||
FileFactory $fileFactory, | ||
StoreManagerInterface $storeManager | ||
) { | ||
$this->_storeManager = $storeManager; | ||
$this->_fileFactory = $fileFactory; | ||
parent::__construct($context, $configStructure, $sectionChecker); | ||
} | ||
|
||
|
||
/** | ||
* Export Servicepoint rates in csv format | ||
* | ||
* @return ResponseInterface|ResultInterface | ||
* @throws LocalizedException | ||
*/ | ||
public function execute() | ||
{ | ||
$fileName = 'sendcloud_servicepointrates.csv'; | ||
/** @var $gridBlock Grid */ | ||
$gridBlock = $this->_view->getLayout()->createBlock(Grid::class); | ||
$website = $this->_storeManager->getWebsite($this->getRequest()->getParam('website')); | ||
if ($this->getRequest()->getParam('conditionName')) { | ||
$conditionName = $this->getRequest()->getParam('conditionName'); | ||
} else { | ||
$conditionName = $website->getConfig('carriers/sendcloud/sen_condition_name'); | ||
} | ||
$gridBlock->setWebsiteId($website->getId())->setSenConditionName($conditionName); | ||
$content = $gridBlock->getCsvFile(); | ||
return $this->_fileFactory->create($fileName, $content, DirectoryList::VAR_DIR); | ||
} | ||
} |
Oops, something went wrong.