following code:
/magento/vendor/magento/module-sales/Block/Adminhtml/Order/Create/Shipping/Method/Form.php
<?php
/**
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Sales\Block\Adminhtml\Order\Create\Shipping\Method;
use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\OfflineShipping\Model\Carrier\Freeshipping;
/**
* Adminhtml sales order create shipping method form block
*
* @author Magento Core Team <[email protected]>
*/
class Form extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
{
/**
* Shipping rates
*
* @var array
*/
protected $_rates;
/**
* Tax data
*
* @var \Magento\Tax\Helper\Data
*/
protected $_taxData = null;
/**
* @var PriceCurrencyInterface
*/
protected $priceCurrency;
protected $orderCreate;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Backend\Model\Session\Quote $sessionQuote
* @param \Magento\Sales\Model\AdminOrder\Create $orderCreate
* @param PriceCurrencyInterface $priceCurrency
* @param \Magento\Tax\Helper\Data $taxData
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Backend\Model\Session\Quote $sessionQuote,
\Magento\Sales\Model\AdminOrder\Create $orderCreate,
PriceCurrencyInterface $priceCurrency,
\Magento\Tax\Helper\Data $taxData,
array $data = []
) {
$this->_taxData = $taxData;
$this->orderCreate = $orderCreate;
parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $data);
}
/**
* Constructor
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setId('sales_order_create_shipping_method_form');
}
/**
* Retrieve quote shipping address model
*
* @return \Magento\Quote\Model\Quote\Address
*/
public function getAddress()
{
return $this->getQuote()->getShippingAddress();
}
/**
* Retrieve array of shipping rates groups
*
* @return array
*/
public function getShippingRates()
{
$usergroup = $this->orderCreate->getCustomerGroupId();
if($usergroup == 1) {
} else {
error_log("Nichtmitgliedsbetrieb");
}
if (empty($this->_rates)) {
$this->_rates = $this->getAddress()->getGroupedAllShippingRates();
}
return $this->_rates;
}
/**
* Rertrieve carrier name from store configuration
*
* @param string $carrierCode
* @return string
*/
public function getCarrierName($carrierCode)
{
if ($name = $this->_scopeConfig->getValue(
'carriers/' . $carrierCode . '/title',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
$this->getStore()->getId()
)
) {
return $name;
}
return $carrierCode;
}
/**
* Retrieve current selected shipping method
*
* @return string
*/
public function getShippingMethod()
{
return $this->getAddress()->getShippingMethod();
}
/**
* Check activity of method by code
*
* @param string $code
* @return bool
*/
public function isMethodActive($code)
{
return $code === $this->getShippingMethod();
}
/**
* Retrieve rate of active shipping method
*
* @return \Magento\Quote\Model\Quote\Address\Rate|false
*/
public function getActiveMethodRate()
{
$rates = $this->getShippingRates();
if (is_array($rates)) {
foreach ($rates as $group) {
foreach ($group as $rate) {
if ($rate->getCode() == $this->getShippingMethod()) {
return $rate;
}
}
}
}
return false;
}
/**
* Get rate request
*
* @return mixed
*/
public function getIsRateRequest()
{
return $this->getRequest()->getParam('collect_shipping_rates');
}
/**
* Get shipping price
*
* @param float $price
* @param bool $flag
* @return float
*/
public function getShippingPrice($price, $flag)
{
/*
$usergroup = $this->orderCreate->getCustomerGroupId();
if($usergroup == 1) {
return "0 €";
} else {
return $this->priceCurrency->convertAndFormat(
$this->_taxData->getShippingPrice(
$price,
$flag,
$this->getAddress(),
null,
$this->getAddress()->getQuote()->getStore()
),
true,
PriceCurrencyInterface::DEFAULT_PRECISION,
$this->getQuote()->getStore()
);
}
*/
return $this->priceCurrency->convertAndFormat(
$this->_taxData->getShippingPrice(
$price,
$flag,
$this->getAddress(),
null,
$this->getAddress()->getQuote()->getStore()
),
true,
PriceCurrencyInterface::DEFAULT_PRECISION,
$this->getQuote()->getStore()
);
}
}
How can I activate free shipping for certain user group? Take a look at getShippingRates();
Thanks!!!
EDIT: the problem is, that it always takes Tablerates-Shipping as Shipment-Method even though the initial order had Freeshipping as Shipping-Method.