Skip to content

Commit

Permalink
2.51.0: #9
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Dec 19, 2017
1 parent 4f6617a commit d5cf0ef
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 388 deletions.
21 changes: 11 additions & 10 deletions app/code/local/Df/Core/LibLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ protected function getScriptsToInclude() {
$base = 'fp' . DS;
return array(
$base . 'compiled'
, $base . '1c'
, $base . 'array'
, $base . 'catalog'
, $base . 'date'
, $base . 'db'
, $base . 'domain'
, $base . 'filesystem'
, $base . 'float'
, $base . 'licensor'
, $base . 'other'
, $base . 'reflection'
, $base . 'validation'
, $base . 'serialize'
, $base . 'state'
, $base . 'store'
, $base . 'text'
, $base . 'validation'
, $base . 'xml'
, $base . 'serialize'
, $base . 'date'
, $base . 'other'
, $base . 'filesystem'
, $base . 'licensor'
, $base . 'domain'
, $base . 'db'
, $base . 'catalog'
, $base . '1c'
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/local/Df/Core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</Df_Core>
</modules>
<df>
<version>2.50.3</version>
<version>2.51.0</version>
<jquery>
<core>
<cdn>//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js</cdn>
Expand Down
9 changes: 9 additions & 0 deletions app/code/local/Df/Core/lib/fp/array.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,15 @@ function df_array_query(array $array, $query, $defaultValue = null) {
return $result;
}

/**
* 2016-09-05
* @used-by \Df_RussianPost_Model_RussianPostCalc_Method::getMethodTitle()
* @param int|string $v
* @param array(int|string => mixed) $map
* @return int|string|mixed
*/
function dftr($v, array $map) {return df_a($map, $v, $v);}

/**
* Отсекает первый элемент массива и возвращает хвост (аналог CDR в Lisp)
* @param array $array
Expand Down
19 changes: 19 additions & 0 deletions app/code/local/Df/Core/lib/fp/float.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* 2016-10-23
* Используемой реализации, видимо, идентична такая: sprintf('%.2F', df_float($value))
* В то же время реализация sprintf('%.2f', df_float($value)) вовсе не идентична используемой,
* потому что она использует десятичный разделитель текущей локали: для России — запятую.
* http://php.net/manual/en/function.sprintf.php
* 3 => 3.00
* 3.333 => 3.33
* 3.300 => 3.30
* https://3v4l.org/AUTCA
*
* @used-by Df_RussianPost_Model_Collector::getMethods()
* @param float $value
* @param int $precision [optional]
* @return string
*/
function dff_2($value, $precision = 2) {return number_format($value, $precision, '.', '');}

10 changes: 5 additions & 5 deletions app/code/local/Df/Core/lib/fp/other.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ function df_magento_version($param1 = null, $param2 = null) {
* В качестве параметра $modelClass можно передавать:
* 1) класс модели в стандартном формате
* 2) класс модели в формате Magento
* @param string $modelClass
* @param string|object $c
* @param array(string => mixed) $parameters [optional]
* @return Mage_Core_Model_Abstract
* @throws Exception
*/
function df_model($modelClass = '', $parameters = array()) {
function df_model($c = '', $parameters = array()) {
/**
* Удаление df_param_string
* ускорило загрузку главной страницы на эталонном тесте
Expand All @@ -262,9 +262,9 @@ function df_model($modelClass = '', $parameters = array()) {
/** @var Mage_Core_Model_Abstract $result */
$result = null;
try {
$result = Mage::getModel($modelClass, $parameters);
$result = is_object($c) ? $c : Mage::getModel($c, $parameters);
if (!is_object($result)) {
df_error('Не найден класс «%s»', $modelClass);
df_error('Не найден класс «%s»', $c);
}
/**
* Обратите внимание, что Mage::getModel
Expand Down Expand Up @@ -295,7 +295,7 @@ function df_model($modelClass = '', $parameters = array()) {
,array(
'%method%' => $methodNameWithClassName
,'%line%' => df_a(df_a($bt, 0), "line")
,'%modelClass%' => $modelClass
,'%modelClass%' => $c
,'%message%' => rm_ets($e)
)
));
Expand Down
99 changes: 40 additions & 59 deletions app/code/local/Df/RussianPost/Model/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,46 @@ protected function getMethods() {
&&
$this->getRateRequest()->getDestinationPostalCode()
) {
foreach ($this->getDomesticApi()->getRatesAsText() as $textualRate) {
/** @var string $textualRate */
df_assert_string($textualRate);
$method = $this->createMethodByTextualRate($textualRate);
$result[]= $method;
/**
* 2017-12-19
* 1) "Модуль «Почта России» поломался,
* потому что используемый им для внутрероссийских отправлений сервис russianpostcalc.ru
* ввёл CAPTCHA (стал требовать «проверочный код»)": https://github.com/magento-russia/2/issues/9
* 2) «API. Метод calc. Расчет стоимости отправки Почтового отправления»:
* http://russianpostcalc.ru/user/myaddr/api/#calc
* 3) «PHP скрипт - пример, вызова метода calc»: http://russianpostcalc.ru/user/rp_calc.zip
*/
/** @var Zend_Http_Client $c */
$c = new Zend_Http_Client('http://russianpostcalc.ru/api_v1.php');
$c->setMethod(Zend_Http_Client::POST);
/**
* 2017-12-19
* Параметры должны идти именно в такой последовательности не только для расчёта `hash`,
* но и в самом запросе HTTP к API, иначе API ответит:
* «10006 auth Ошибка доступа (не верная подпись)!».
* https://df.tips/t/268
*/
$p = array(
// 2017-12-19 «API ключ Вашего аккаунта»
'apikey' => '21ae2a1cd5dd3493a99a841658ea8bc8'
// 2017-12-19 «Вызываемый метод»
,'method' => 'calc'
// 2017-12-19 «Почтовый индекс отправителя»
,'from_index' => $this->getRateRequest()->getOriginPostalCode()
// 2017-12-19 «Почтовый индекс получателя»
,'to_index' => $this->getRateRequest()->getDestinationPostalCode()
,'weight' => dff_2($this->getRateRequest()->getWeightInKilogrammes())
// 2017-12-19 «Объявленная ценность отправления, руб»
,'ob_cennost_rub' => rm_currency()->convertFromBaseToRoubles($this->declaredValueBase())
); /** @var array(string => string) $p */
// 2017-12-19 «Обязательный аргумент, если аутентификация по методу API ключ + API пароль»
$c->setParameterPost($p + ['hash' => md5(implode('|', array_merge($p, array('braKecU3'))))]);
$res = df_json_decode($c->request()->getBody()); /** @var array(string => mixed) $res */
if ('done' !== df_a_deep($res, 'msg/type')) {
df_error(df_a_deep($res, 'msg/text'));
}
foreach ($res['calc'] as $rate) { /** @var array(string => string|float) $rate */
$result[]= $this->createMethod(new Df_RussianPost_Model_RussianPostCalc_Method($rate));
}
}
try {
Expand Down Expand Up @@ -56,59 +91,5 @@ protected function getMethods() {
return $this->{__METHOD__};
}

/**
* @param string $textualRate
* @return Df_Shipping_Model_Method
*/
private function createMethodByTextualRate($textualRate) {
/** @var Df_Shipping_Model_Method $result */
$result = null;
/** @var string $methodClass */
$methodClass = null;
/** @var string $methodTitle */
$methodTitle = null;
/** @var int $titleLength */
$titleLength = 0;
foreach ($this->getCarrier()->getAllowedMethodsAsArray() as $methodData) {
/** @var array $methodData */
df_assert_array($methodData);
/** @var string $title */
$title = df_a($methodData, 'title');
df_assert_string($title);
if (rm_starts_with($textualRate, $title)) {
/** @var int $currentTitleLength */
$currentTitleLength = mb_strlen($title);
if ($currentTitleLength > $titleLength) {
$methodClass = df_a($methodData, 'class');
$methodTitle = $title;
}
}
}
df_assert_string($methodClass);
df_assert_string($methodTitle);
/** @var Df_RussianPost_Model_RussianPostCalc_Method $result */
$result = $this->createMethod($methodClass, $methodTitle);
df_assert($result instanceof Df_RussianPost_Model_RussianPostCalc_Method);
$result->setRateAsText($textualRate);
return $result;
}

/** @return Df_RussianPost_Model_RussianPostCalc_Api */
private function getDomesticApi() {
if (!isset($this->{__METHOD__})) {
$this->{__METHOD__} = Df_RussianPost_Model_RussianPostCalc_Api::i(array(
Df_RussianPost_Model_RussianPostCalc_Api::P__WEIGHT =>
$this->getRateRequest()->getWeightInKilogrammes()
,Df_RussianPost_Model_RussianPostCalc_Api::P__DECLARED_VALUE =>
rm_currency()->convertFromBaseToRoubles($this->declaredValueBase())
,Df_RussianPost_Model_RussianPostCalc_Api::P__SOURCE__POSTAL_CODE =>
$this->getRateRequest()->getOriginPostalCode()
,Df_RussianPost_Model_RussianPostCalc_Api::P__DESTINATION__POSTAL_CODE =>
$this->getRateRequest()->getDestinationPostalCode()
));
}
return $this->{__METHOD__};
}

const _CLASS = __CLASS__;
}
83 changes: 0 additions & 83 deletions app/code/local/Df/RussianPost/Model/RussianPostCalc/Api.php

This file was deleted.

Loading

0 comments on commit d5cf0ef

Please sign in to comment.