Skip to content

Commit

Permalink
v0.2.3 toggle shipping options
Browse files Browse the repository at this point in the history
  • Loading branch information
reindertvetter committed Jan 27, 2017
1 parent a453f68 commit 64c1e1d
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 132 deletions.
58 changes: 58 additions & 0 deletions Block/Sales/Index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
/**
* Short_description
*
* LICENSE: This source file is subject to the Creative Commons License.
* It is available through the world-wide-web at this URL:
* http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US
*
* If you want to add improvements, please create a fork in our GitHub:
* https://github.com/myparcelnl
*
* @author Reindert Vetter <reindert@myparcel.nl>
* @copyright 2010-2017 MyParcel
* @license http://creativecommons.org/licenses/by-nc-nd/3.0/nl/deed.en_US CC BY-NC-ND 3.0 NL
* @link https://github.com/myparcelnl/magento
* @since File available since Release 0.1.0
*/

namespace MyParcelNL\Magento\Block\Sales;

use Magento\Backend\Block\Template;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\App\ObjectManager;

class Index extends Template
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;

/**
* @var \MyParcelNL\Magento\Helper\Data
*/
private $helper;

/**
* @param Context $context
* @param array $data
*/
public function __construct(Context $context, array $data = [])
{
$this->objectManager = ObjectManager::getInstance();
$this->helper = $this->objectManager->get('\MyParcelNL\Magento\Helper\Data');
parent::__construct($context, $data);
}

public function getAjaxUrl()
{
return $this->_urlBuilder->getUrl('myparcelnl/order/MassTrackTraceLabel');
}

public function getSettings()
{
$settings = $this->helper->getStandardConfig('print');
return json_encode($settings);
}
}
42 changes: 20 additions & 22 deletions Block/Sales/NewShipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,35 @@
class NewShipment extends AbstractItems
{
/**
* @var \Magento\Framework\ObjectManagerInterface
* @var Order
*/
private $objectManager;
private $order;

/**
* @var Order
* @var \MyParcelNL\Magento\Model\Source\DefaultOptions
*/
private $modelOrder;

private $defaultOptions;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry
* @param \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration
* @param \Magento\Framework\Registry $registry
* @param array $data
*
* @throws \LogicException
* @param \Magento\Framework\ObjectManagerInterface $objectManager
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
\Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration,
\Magento\Framework\Registry $registry,
array $data = []
\Magento\Framework\ObjectManagerInterface $objectManager
) {
$this->objectManager = ObjectManager::getInstance();
$this->modelOrder = $this->objectManager->create('Magento\Sales\Model\Order');

$orderId = $context->getRequest()->getParam('order_id', null);
if ($orderId == null) {
throw new \LogicException('No order id found');
}
// Set order
$this->order = $registry->registry('current_shipment')->getOrder();

$this->defaultOptions = new DefaultOptions(
$this->modelOrder->load($orderId),
$this->objectManager->get('\MyParcelNL\Magento\Helper\Data')
$this->order,
$objectManager->get('\MyParcelNL\Magento\Helper\Data')
);

parent::__construct($context, $stockRegistry, $stockConfiguration, $registry);
Expand All @@ -76,8 +67,7 @@ public function __construct(
*/
public function getDefaultOption($option)
{
return $this->defaultOptions
->getDefault($option);
return $this->defaultOptions->getDefault($option);
}

/**
Expand All @@ -87,7 +77,15 @@ public function getDefaultOption($option)
*/
public function getDefaultInsurance()
{
return $this->defaultOptions
->getDefaultInsurance();
return $this->defaultOptions->getDefaultInsurance();
}

/**
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getCountry()
{
return $this->order->getShippingAddress()->getCountryId();
}
}
10 changes: 0 additions & 10 deletions Block/Sales/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,4 @@ public function __construct(Context $context, array $data = [])
parent::__construct($context, $data);
}

public function getAjaxUrl()
{
return $this->_urlBuilder->getUrl('myparcelnl/order/MassTrackTraceLabel');
}

public function getSettings()
{
$settings = $this->helper->getStandardConfig('print');
return json_encode($settings);
}
}
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": "myparcelnl/magento",
"description": "A Magento 2 module that creates MyParcel labels",
"type": "magento2-module",
"version": "v0.1.2",
"version": "v0.1.3",
"homepage": "https://www.myparcel.nl",
"tags": ["MyParcel", "My Parcel", "Post NL", "PostNL"],
"license": "CC BY-NC-ND 3.0 NL",
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/layout/sales_order_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</head>
<body>
<referenceContainer name="content">
<block class="MyParcelNL\Magento\Block\Sales\View" name="myparcelnl.order" template="order.phtml" after="-" />
<block class="MyParcelNL\Magento\Block\Sales\Index" name="myparcelnl.order" template="order.phtml" after="-" />
</referenceContainer>
</body>
</page>
14 changes: 14 additions & 0 deletions view/adminhtml/layout/sales_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="order_shipping_view">
<block class="MyParcelNL\Magento\Block\Sales\Index" name="myparcelnl.order" template="order_view.phtml"/>
</referenceBlock>
</body>
</page>
184 changes: 93 additions & 91 deletions view/adminhtml/templates/new_shipment.phtml
Original file line number Diff line number Diff line change
@@ -1,94 +1,96 @@
<?php /** @var MyParcelNL\Magento\Block\Sales\NewShipment $block */ ?>
<!-- MyParcel options -->
<div class="admin__field field-mypa_package_type">
<label class="admin__field-label">
<span>MyParcel options</span>
</label>
<div class="admin__field-control">
<div class="admin__field admin__field-option">
<input type="radio" class="admin__control-radio" id="mypa_package_type-package" name="mypa[package_type]" value="1" checked="checked">
<label class="admin__field-label" for="mypa_package_type-package">Package</label>
</div>
<div class="admin__field admin__field-option">
<input type="radio" class="admin__control-radio" id="mypa_package_type-mailbox" name="mypa[package_type]" value="2">
<label class="admin__field-label" for="mypa_package_type-mailbox">Mailbox</label>
</div>
<div class="admin__field admin__field-option">
<input type="radio" class="admin__control-radio" id="mypa_package_type-letter" name="mypa[package_type]" value="3">
<label class="admin__field-label" for="mypa_package_type-letter">Letter</label>
<?php if ($block->getCountry() == 'NL'): ?>
<!-- MyParcel options -->
<div class="admin__field field-mypa_package_type mypa_nl-toggle">
<label class="admin__field-label">
<span>MyParcel options</span>
</label>
<div class="admin__field-control">
<div class="admin__field admin__field-option">
<input type="radio" class="admin__control-radio" id="mypa_package_type-package" name="mypa[package_type]" value="1" checked="checked">
<label class="admin__field-label" for="mypa_package_type-package">Package</label>
</div>
<div class="admin__field admin__field-option">
<input type="radio" class="admin__control-radio" id="mypa_package_type-mailbox" name="mypa[package_type]" value="2">
<label class="admin__field-label" for="mypa_package_type-mailbox">Mailbox</label>
</div>
<div class="admin__field admin__field-option">
<input type="radio" class="admin__control-radio" id="mypa_package_type-letter" name="mypa[package_type]" value="3">
<label class="admin__field-label" for="mypa_package_type-letter">Letter</label>
</div>
</div>
</div>
</div>
<div class="field choice admin__field admin__field-option field-mypa_only_recipient">
<input id="mypa_only_recipient"
class="admin__control-checkbox"
name="mypa[only_recipient]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('only_recipient') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_only_recipient">
<span><?php /* @escapeNotVerified */ echo __('Home address only') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_signature">
<input id="mypa_signature"
class="admin__control-checkbox"
name="mypa[signature]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('signature') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_signature">
<span><?php /* @escapeNotVerified */ echo __('Signature on receipt') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_return">
<input id="mypa_return"
class="admin__control-checkbox"
name="mypa[return]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('return') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_return">
<span><?php /* @escapeNotVerified */ echo __('Return if no answer') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_large_format">
<input id="mypa_large_format"
class="admin__control-checkbox"
name="mypa[large_format]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('large_format') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_large_format">
<span><?php /* @escapeNotVerified */ echo __('Large package') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_insurance">
<?php $defaultInsurance = $block->getDefaultInsurance();?>
<select name="mypa[insurance]" id="mypa_insurance" class="required product-custom-option admin__control-select" title="" >
<option value="0" ><?php echo __('No insurance') ?></option>
<option value="50" <?= $defaultInsurance == 50 ? 'selected="selected"' : '';?> >€ 50</option>
<option value="250" <?= $defaultInsurance == 250 ? 'selected="selected"' : '';?> >€ 250</option>
<option value="500" <?= $defaultInsurance == 500 ? 'selected="selected"' : '';?> >€ 500</option>
<option value="1000" >€ 1000</option>
<option value="1500" >€ 1500</option>
<option value="2000" >€ 2000</option>
<option value="2500" >€ 2500</option>
<option value="3000" >€ 3000</option>
<option value="3500" >€ 3500</option>
<option value="4000" >€ 4000</option>
<option value="4500" >€ 4500</option>
<option value="5000" >€ 5000</option>
</select>
</div>
<script type="text/x-magento-init">
{
".page-footer": {
"myparcelnl_newshipment": {}
}
}
</script>
<div class="field choice admin__field admin__field-option field-mypa_only_recipient mypa_package-toggle">
<input id="mypa_only_recipient"
class="admin__control-checkbox"
name="mypa[only_recipient]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('only_recipient') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_only_recipient">
<span><?php /* @escapeNotVerified */ echo __('Home address only') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_signature mypa_package-toggle">
<input id="mypa_signature"
class="admin__control-checkbox"
name="mypa[signature]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('signature') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_signature">
<span><?php /* @escapeNotVerified */ echo __('Signature on receipt') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_return mypa_package-toggle">
<input id="mypa_return"
class="admin__control-checkbox"
name="mypa[return]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('return') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_return">
<span><?php /* @escapeNotVerified */ echo __('Return if no answer') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_large_format mypa_package-toggle">
<input id="mypa_large_format"
class="admin__control-checkbox"
name="mypa[large_format]"
value="1"
type="checkbox"
<?= $block->getDefaultOption('large_format') == true ? 'checked="checked"' : '';?>
/>
<label class="admin__field-label"
for="mypa_large_format">
<span><?php /* @escapeNotVerified */ echo __('Large package') ?></span></label>
</div>
<div class="field choice admin__field admin__field-option field-mypa_insurance mypa_package-toggle">
<?php $defaultInsurance = $block->getDefaultInsurance();?>
<select name="mypa[insurance]" id="mypa_insurance" class="required product-custom-option admin__control-select" title="" >
<option value="0" ><?php echo __('No insurance') ?></option>
<option value="50" <?= $defaultInsurance == 50 ? 'selected="selected"' : '';?> >€ 50</option>
<option value="250" <?= $defaultInsurance == 250 ? 'selected="selected"' : '';?> >€ 250</option>
<option value="500" <?= $defaultInsurance == 500 ? 'selected="selected"' : '';?> >€ 500</option>
<option value="1000" >€ 1000</option>
<option value="1500" >€ 1500</option>
<option value="2000" >€ 2000</option>
<option value="2500" >€ 2500</option>
<option value="3000" >€ 3000</option>
<option value="3500" >€ 3500</option>
<option value="4000" >€ 4000</option>
<option value="4500" >€ 4500</option>
<option value="5000" >€ 5000</option>
</select>
</div>
<script type="text/x-magento-init">
{
".page-footer": {
"myparcelnl_newshipment": {}
}
}
</script>
<?php endif; ?>
1 change: 1 addition & 0 deletions view/adminhtml/templates/order_view.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test12345tgfv
Loading

0 comments on commit 64c1e1d

Please sign in to comment.