Использовать индивидуальный способ доставки на основе атрибутов продукта - PullRequest
0 голосов
/ 19 июня 2020

Я пытаюсь получить настраиваемый атрибут продукта в свой настраиваемый модуль доставки. Но не смог этого сделать. Я задавал различные вопросы на форуме, но проблема все еще не решена. Но ничего не работает. Я создаю настраиваемый атрибут с именем: ars_freight_class в атрибуте продукта и пытаюсь получить значение в моем методе доставки, но он показывает null, когда я использую $ items-> getProduct () -> getAttributeText ('ars_freight_class'); он дает Null, а также при использовании только getAttribute (('ars_freight_class'), который также не работает. Затем я добавил новый атрибут в продукт с именем Freight и с помощью getFreight (); также показывает null. Так что любезно помогите мне в этом, как Я могу получить значение настраиваемого атрибута продукта в своей модели. Я использую раскрывающийся атрибут и правильно назначен в наборе атрибутов. App \ code {MODULE_name} \ CustomShipping \ Model \ Carrier \ rlcarriers. php

namespace Raveinfosys \ Rlcarriers \ Model \ Carrier;

use Raveinfosys \ Rlcarriers \ Model \ Carrier;

класс Rlcarriers расширяет AbstractCarrierModel {

/**
 * Carrier's code
 *
 * @var string
 */

protected $_code = 'rlcarriers';

/**
 * Fields that should be replaced in debug with '***'
 *
 * @var array
 */
protected $_debugReplacePrivateDataKeys = ['APIKey'];

/**
 * Request Quote URL
 */
protected $_requestQuoteUrl = 'http://api.rlcarriers.com/1.0.1/RateQuoteService.asmx?WSDL';
protected $_apiKey = null;
protected $_debugData = [];

public function collectFreightRate()
{
    $request = $this->buildRequest();
    $this->_debugData['request'] = $request;
    try {
        $rates = $this->postRequest($request);
    } catch (\Exception $e) {
        return false;
    }
    return $rates;
}

public function buildRequest()
{
    $_originZip = $this->_dataHelper->getOriginPostcode();
    $_defaultShipClass = $this->_dataHelper->getShipclass();

    $this->_apiKey = $this->_dataHelper->decrypt($this->getConfigData('apikey'));

    if (!$this->_apiKey) {
        return false;
    }
    $request["APIKey"] = $this->_apiKey;
    $request["QuoteType"] = "Domestic";
    $request["CODAmount"] = "0";

    $request["Origin"] = [
        "City" => "",
        "StateOrProvince" => "",
        "ZipOrPostalCode" => trim($_originZip),
        "CountryCode" => $this->_dataHelper->getCountryISO3Code($this->_dataHelper->getOriginCountry())
    ];

    $request["Destination"] = [
        "City" => "",
        "StateOrProvince" => "",
        "ZipOrPostalCode" => trim($this->_request->getDestPostcode()),
        "CountryCode" => $this->_dataHelper->getCountryISO3Code($this->_request->getDestCountryId()),
    ];
    $request["DeclaredValue"] = 0;

    $request["OverDimensionPcs"] = 0;

    $items = [];
    $cn = 0;
    foreach ($this->getItems() as $item) {
        $items[$cn]['Class'] = (float) ($this->_dataHelper->getShipclass());
        $items[$cn]['Weight'] = (float) ceil($item->getProduct()->getWeight() * $item->getQty());
        $items[$cn]['Freight'] = $items->getProduct()->getFreight();
       $items[$cn]['Freight'] = $items->getProduct()->getAttributeText('ars_freight_class');
         $items[$cn]['Height'] = (float) $item->getProduct()->getPrice();
        $items[$cn]['Width'] =  $item->getProduct()->getVisibility();
        $items[$cn]['Length'] = (float) $item->getProduct()->getFreightLength();
    }


    $request["Accessorials"] = [];

    $request["Items"] = $items;

    return $request;
}

public function postRequest($request)
{
    try {
        $client = new \Zend\Soap\Client($this->_requestQuoteUrl);
        $response = $client->GetRateQuote(["APIKey" => $this->_apiKey, "request" => $request]);
        $this->_debugData['result'] = $response;
        $_results = $this->parseXmlResponse($response);
    } catch (\Exception $e) {
        $this->_debugData['result'] = $e->getMessage();
        return false;
    }
    $this->debugRlcData($this->_debugData);
    return $_results;
}

public function parseXmlResponse($response)
{
    $_rates = [];
    try {
        $_result = $response->GetRateQuoteResult->Result;
        $_rlcRates = $_result->ServiceLevels->ServiceLevel;
    } catch (\Exception $e) {
        return $_rates;
    }
    $_allowdMethods = $this->getConfigData('allowed_methods_rl');
    if (is_array($_rlcRates)) {
        $_methods = explode(',', $_allowdMethods);
        foreach ($_rlcRates as $_rlcRate) {
            if (!in_array($_rlcRate->Code, $_methods)) {
                continue;
            }
            $_rate = preg_replace('/[^0-9.]* /', '', str_replace('$', '', $_rlcRate->NetCharge));
            $_rates[] = [
                'rate'      => $_rate,
                'method'    => $_rlcRate->Title,
                'code'      => $_rlcRate->Code,
                'carrier'   => $this->_code
            ];
        }
    } else {
        $_rate = preg_replace('/[^0-9.]*/', '', str_replace('$', '', $_result->ServiceLevels->ServiceLevel->NetCharge));
        $_rates[] = [
            'rate'      => $_rate,
            'carrier'   => $this->_code,
            'method'    => $_result->ServiceLevels->ServiceLevel->Title,
            'code'      => $_result->ServiceLevels->ServiceLevel->Code
        ];
    }
    return $_rates;
}

}

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...