cancel
Showing results for 
Search instead for 
Did you mean: 

[backend] How to Configure Flat Rate Shipping Method in Magento 2

SOLVED

[backend] How to Configure Flat Rate Shipping Method in Magento 2

Hello, i need help with magento 2.

 

i am developing a module in magento 2.2.2.

 

http://docs.magento.com/m2/ee/user_guide/shipping/shipping-flat-rate.html

in my module i need modify values of shipping-flat-rate.

eg: title, price.

 

how get and update values of shipping-flat-rate since my module.

thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: [backend] How to Configure Flat Rate Shipping Method in Magento 2

<?php
namespace Proveedor\Gnuxdar\Block\Adminhtml\Filter\Edit\Tab;

use Magento\Backend\Block\Widget\Form\Generic;
...

class Info extends Generic implements TabInterface
{
    protected $_scopeConfigInterface;

       ...
    public function __construct(
        ...
        )
    {
        parent::__construct($context, $registry, $formFactory, $data);
        $this->_scopeConfigInterface = $scopeConfigInterface;
        $this->_countryCollectionFactory = $countryCollectionFactory;
    }

    protected function _prepareForm()
    {
        $path = 'carriers/flatrate/';
        $country = $this->_scopeConfigInterface->getValue($path.'specificcountry', \Magento\Store\Model\ScopeInterface:Smiley FrustratedCOPE_STORE);

        $form = $this->_formFactory->create(['data'=>['id'=>'edit_form', 'action'=>$this->....
        
        $fieldset->addField(
            'enabled',
            'select',
            [
                'name'=>'enabled',
                'label'=>__('Enabled'),
                'required'=>true,
                'values'=>array(0=>'No', 1=>'Yes'),
                'value'=>$this->_scopeConfigInterface->getValue($path.'active', \Magento\Store\Model\ScopeInterface:Smiley FrustratedCOPE_STORE)
            ]
        );

 

for more info, my https://www.twitter.com/gnuxdar

View solution in original post

2 REPLIES 2

Re: [backend] How to Configure Flat Rate Shipping Method in Magento 2

Hi there,

 

We’d recommend creating a separate proprietary/own shipping method based on Magento\OfflineShipping\Model\Carrier\Flatrate, and rewrite getShippingPrice() method in it. Enter your conditions with the calculations there.

 

---------------------------------------------------------

If you've found one of our answers useful, please give 'Kudos' or 'Accept as Solution'.

Re: [backend] How to Configure Flat Rate Shipping Method in Magento 2

<?php
namespace Proveedor\Gnuxdar\Block\Adminhtml\Filter\Edit\Tab;

use Magento\Backend\Block\Widget\Form\Generic;
...

class Info extends Generic implements TabInterface
{
    protected $_scopeConfigInterface;

       ...
    public function __construct(
        ...
        )
    {
        parent::__construct($context, $registry, $formFactory, $data);
        $this->_scopeConfigInterface = $scopeConfigInterface;
        $this->_countryCollectionFactory = $countryCollectionFactory;
    }

    protected function _prepareForm()
    {
        $path = 'carriers/flatrate/';
        $country = $this->_scopeConfigInterface->getValue($path.'specificcountry', \Magento\Store\Model\ScopeInterface:Smiley FrustratedCOPE_STORE);

        $form = $this->_formFactory->create(['data'=>['id'=>'edit_form', 'action'=>$this->....
        
        $fieldset->addField(
            'enabled',
            'select',
            [
                'name'=>'enabled',
                'label'=>__('Enabled'),
                'required'=>true,
                'values'=>array(0=>'No', 1=>'Yes'),
                'value'=>$this->_scopeConfigInterface->getValue($path.'active', \Magento\Store\Model\ScopeInterface:Smiley FrustratedCOPE_STORE)
            ]
        );

 

for more info, my https://www.twitter.com/gnuxdar