2

I am using webkul shipping module to moderate my shipping method, here I have no backend field to put the shipping price into. I'll bellow put my php class. Where should I implement the backend shipping price field to be available to customize from backend admin.

<?php
namespace Webkul\Customshipping\Model;

use Magento\Quote\Model\Quote\Address\RateResult\Error;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
use Magento\Shipping\Model\Carrier\CarrierInterface;
use Magento\Shipping\Model\Rate\Result;
use Magento\Shipping\Model\Simplexml\Element;
use Magento\Ups\Helper\Config;
use Magento\Framework\Xml\Security;


class Carrier extends AbstractCarrierOnline implements 
CarrierInterface
{
const CODE = 'wkcustomshipping';
protected $_code = self::CODE;
protected $_request;
protected $_result;
protected $_baseCurrencyRate;
protected $_xmlAccessRequest;
protected $_localeFormat;
protected $_logger;
protected $configHelper;
protected $_errors = [];
protected $_isFixed = true;

public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory 
$rateErrorFactory,
\Psr\Log\LoggerInterface $logger,
Security $xmlSecurity,
\Magento\Shipping\Model\Simplexml\ElementFactory $xmlElFactory,
\Magento\Shipping\Model\Rate\ResultFactory $rateFactory,
\Magento\Quote\Model\Quote\Address\RateResult\MethodFactory 
$rateMethodFactory,
\Magento\Shipping\Model\Tracking\ResultFactory $trackFactory,
\Magento\Shipping\Model\Tracking\Result\ErrorFactory 
$trackErrorFactory,
\Magento\Shipping\Model\Tracking\Result\StatusFactory 
$trackStatusFactory,
\Magento\Directory\Model\RegionFactory $regionFactory,
\Magento\Directory\Model\CountryFactory $countryFactory,
\Magento\Directory\Model\CurrencyFactory $currencyFactory,
\Magento\Directory\Helper\Data $directoryData,
\Magento\CatalogInventory\Api\StockRegistryInterface $stockRegistry,
    \Magento\Framework\Locale\FormatInterface $localeFormat,
    Config $configHelper,
    array $data = []
) {
    $this->_localeFormat = $localeFormat;
    $this->configHelper = $configHelper;
    parent::__construct(
        $scopeConfig,
        $rateErrorFactory,
        $logger,
        $xmlSecurity,
        $xmlElFactory,
        $rateFactory,
        $rateMethodFactory,
        $trackFactory,
        $trackErrorFactory,
        $trackStatusFactory,
        $regionFactory,
        $countryFactory,
        $currencyFactory,
        $directoryData,
        $stockRegistry,
        $data
    );
}
protected function _doShipmentRequest(\Magento\Framework\DataObject $request)
{
}

public function getAllowedMethods()
{
}

public function collectRates(RateRequest $request)
{   
    $result = $this->_rateFactory->create();

    /*store shipping in session*/
    $method = $this->_rateMethodFactory->create();
    $method->setCarrier($this->_code);
    $method->setCarrierTitle('Arpico testing shipping');
    /* Use method name */
    $method->setMethod($this->_code);
    $method->setMethodTitle('Arpico testing shipping');
    $method->setCost(250);
    $method->setPrice(250);


    $objectManager = 
    \Magento\Framework\App\ObjectManager::getInstance();
    $cart = $objectManager->get('\Magento\Checkout\Model\Cart'); 

    $subTotal = $cart->getQuote()->getSubtotal();
    $grandTotal = $cart->getQuote()->getGrandTotal();
    $store = $cart->getQuote()->getStore()->getId();


    return $result; 
}

public function proccessAdditionalValidation(\Magento\Framework\DataObject $request) {
    return true;
}
}  
2
  • It should be on your system.xml , defined with a default value using config.xml
    – fmsthird
    Jan 24, 2019 at 9:32
  • do not use objectmanager. use DI Jan 24, 2019 at 10:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.