Beispiel #1
0
 /**
  * 2016-05-04
  * @param int $cartId
  * @param IPayment $paymentMethod
  * @param IAddress|null $billingAddress
  * @return mixed
  * @throws CouldNotSaveException
  */
 public function registered($cartId, IPayment $paymentMethod, IAddress $billingAddress = null)
 {
     /** @var IRegistered|Registered $iRegistered */
     $iRegistered = df_o(IRegistered::class);
     $iRegistered->savePaymentInformation($cartId, $paymentMethod, $billingAddress);
     return PlaceOrderInternal::p($cartId, false);
 }
Beispiel #2
0
 /**
  * 2016-04-10
  * It is implemented by analogy with @see \Magento\Backend\Model\Auth::login()
  * https://github.com/magento/magento2/blob/052e789/app/code/Magento/Backend/Model/Auth.php#L137-L182
  *
  * @param string $email
  * @return void
  * @throws \Magento\Framework\Exception\AuthenticationException
  */
 public function loginByEmail($email)
 {
     $this->_initCredentialStorage();
     /** @var \Magento\Backend\Model\Auth\Credential\StorageInterface|\Magento\User\Model\User $user */
     $user = $this->getCredentialStorage();
     $user->{\Df\User\Plugin\Model\User::LOGIN_BY_EMAIL} = true;
     $user->login($email, null);
     if ($user->getId()) {
         /** @var \Magento\Backend\Model\Auth\StorageInterface|\Magento\Backend\Model\Auth\Session $authSession */
         $authSession = $this->getAuthStorage();
         $authSession->setUser($user);
         $authSession->processLogin();
         //$cookieManager->setSensitiveCookie($session->getName(), session_id());
         $_COOKIE[$authSession->getName()] = session_id();
         /** @var SessionManagerInterface|\Magento\Backend\Model\Session $session */
         $session = df_o(SessionManagerInterface::class);
         $session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, df_request('form_key'));
         df_dispatch('backend_auth_user_login_success', ['user' => $user]);
         /**
          * 2016-04-10
          * Обязательно, иначе авторизация работать не будет.
          * https://mage2.pro/t/1199
          */
         /** @var SecurityPlugin $securityPlugin */
         $securityPlugin = df_o(SecurityPlugin::class);
         $securityPlugin->afterLogin($this);
     }
 }
Beispiel #3
0
/**
 * 2015-12-28
 * @param int|string|null|bool|StoreInterface $store [optional]
 * @return array(string => string)
 */
function df_currencies_ctn($store = null)
{
    return dfcf(function ($store = null) {
        $store = df_store($store);
        /** @var Currency $currency */
        $currency = df_o(Currency::class);
        /** @var string[] $codes */
        $codes = df_currencies_codes_allowed($store);
        // 2016-02-17
        // $rates ниже не содержит базовую валюту.
        /** @var string $baseCode */
        $baseCode = $store->getBaseCurrency()->getCode();
        /** @var array(string => float) $rates */
        $rates = $currency->getCurrencyRates($store->getBaseCurrency(), $codes);
        /** @var array(string => string) $result */
        $result = [];
        foreach ($codes as $code) {
            /** @var string $code */
            if ($baseCode === $code || isset($rates[$code])) {
                $result[$code] = df_currency_name($code);
            }
        }
        return $result;
    }, func_get_args());
}
Beispiel #4
0
 /**
  * 2016-07-01
  * @return \Composer\Composer
  */
 private function composer()
 {
     if (!isset($this->{__METHOD__})) {
         /** @var ComposerFactory $factory */
         $factory = df_o(ComposerFactory::class);
         $this->{__METHOD__} = $factory->create();
     }
     return $this->{__METHOD__};
 }
Beispiel #5
0
/**
 * 2016-01-26
 * @param string $entityType
 * @param int|string|null|bool|StoreInterface $store [optional]
 * @return _Meta|Meta
 */
function df_sales_seq_meta($entityType, $store = null)
{
    return dfcf(function ($entityType, $store = null) {
        /** @var RMeta $r */
        $r = df_o(RMeta::class);
        /**
         * 2016-01-26
         * По аналогии с @see \Magento\SalesSequence\Model\Manager::getSequence()
         * https://github.com/magento/magento2/blob/d50ee5/app/code/Magento/SalesSequence/Model/Manager.php#L48
         */
        return $r->loadByEntityTypeAndStore($entityType, df_store_id($store));
    }, func_get_args());
}
Beispiel #6
0
 /**
  * 2016-07-01
  * @override
  * @see \Magento\Config\Block\System\Config\Form\Fieldset::_getHeaderCommentHtml()
  * https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Config/Block/System/Config/Form/Fieldset.php#L166-L175
  * @used-by \Magento\Config\Block\System\Config\Form\Fieldset::_getHeaderHtml()
  * https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Config/Block/System/Config/Form/Fieldset.php#L121
  * @param AE|F $element
  * @return string
  */
 protected function _getHeaderCommentHtml($element)
 {
     /** @var string|null $infoClass */
     $infoClass = dfa_deep($element->getData(), 'group/dfExtension');
     /** @var string $result */
     if (!$infoClass) {
         $result = parent::_getHeaderCommentHtml($element);
     } else {
         /** @var \Df\Config\Ext $extensionInfo */
         $info = df_o($infoClass);
         $result = df_tag('div', 'comment', df_tag_ab(__('Have a question?'), $info->url()));
     }
     return $result;
 }
Beispiel #7
0
 /**
  * 2016-11-20
  * У класса @see \Magento\Framework\Data\Form\Element\AbstractElement
  * метод getComment() — магический.
  * К магическим методам плагины не применяются.
  * Поэтому для задействования плагина необходимо унаследоваться от класса ядра
  * и явно объявить в своём классе метод getComment().
  * Примеры:
  * @see \Df\Framework\Form\Element\Checkbox::getComment()
  * @see \Df\Framework\Form\Element\Text::getComment()
  * @used-by \Magento\Config\Block\System\Config\Form\Field::_renderValue()
  * https://github.com/magento/magento2/blob/2.1.0/app/code/Magento/Config/Block/System/Config/Form/Field.php#L82-L84
  * @param Sb $sb
  * @param string $result
  * @return string
  */
 public function afterGetComment(Sb $sb, $result)
 {
     /** @var string|null $vc */
     $vc = df_fe_fc($sb, 'dfValidator');
     if ($vc) {
         /** @var \Df\Framework\IValidator $v */
         $v = df_o($vc);
         /** @var Phrase|Phrase[]|true $messages */
         $messages = $v->check($sb);
         if (true !== $messages) {
             $result .= df_tag_list(df_array($messages), false, 'df-enabler-warnings');
         }
     }
     return $result;
 }
Beispiel #8
0
 /**
  * 2016-07-18
  * @return mixed|null
  * @throws CouldNotSaveException
  */
 private function _place()
 {
     /** @var IQM|QM $qm */
     $qm = df_o(IQM::class);
     /** @var mixed $result */
     try {
         BillingAddress::disable(!$this->ss()->askForBillingAddress());
         try {
             /** @var int $orderId */
             $orderId = $qm->placeOrder($this->quoteId());
         } finally {
             BillingAddress::restore();
         }
         $result = df_order($orderId)->getPayment()->getAdditionalInformation(PlaceOrder::DATA);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__($this->message($e)), $e);
     }
     return $result;
 }
Beispiel #9
0
/**
 * 2015-12-29
 * @return \Magento\Framework\View\Asset\Source
 */
function df_asset_source()
{
    return df_o(\Magento\Framework\View\Asset\Source::class);
}
Beispiel #10
0
 /**
 * 2015-11-30
 * 2015-12-13
 * Обратите внимание, что $label может быть как пустой строкой, так и null,
 * и система будет вести себя по-разному в этих случаях.
 * Если $label равно null, то подпись у элемента будет отсутствовать.
 * Если $label равно пустой строке, то у элемента будет пустая подпись:
 * пустые теги <label><span></span></label>
 * Пустая подпись позволяет нам задействовать в качестве подписи FontAwesome:
 * мы цепляем к пустому тегу label правила типа:
 			> label:not(.addafter) {
 				display: inline-block;
 				font-family: FontAwesome;
 				// http://fortawesome.github.io/Font-Awesome/icon/text-width/
 				&:before {content: "\f035";}
 			}
 *
 * 2015-12-28
 * Добавил возможность передачи в качестве $values простого одномерного массива,
 * например: $this->select('decimalSeparator', 'Decimal Separator', ['.', ',']);
 *
 * @used-by \Df\Framework\Form\Element\Fieldset::yesNo()
 * @param string $name
 * @param string|null|Phrase $label
 * @param array(array(string => string|int))|string[]|string|OptionSourceInterface $values
 * @param array(string => mixed)|string $data [optional]
 * @param string|null $type [optional]
 * @return \Magento\Framework\Data\Form\Element\Select|E
 */
 protected function select($name, $label, $values, $data = [], $type = 'select')
 {
     if (!is_array($values)) {
         if (!$values instanceof OptionSourceInterface) {
             $values = df_o($values);
         }
         df_assert($values instanceof OptionSourceInterface);
         $values = $values->toOptionArray();
     }
     if (!is_array($data)) {
         $data = ['note' => $data];
     }
     return $this->field($name, $type, $label, $data + ['values' => df_a_to_options($values)]);
 }
Beispiel #11
0
/**
 * 2016-07-30
 * @return ScopePool
 */
function df_scope_pool()
{
    return df_o(ScopePool::class);
}
Beispiel #12
0
/** @return string */
function df_visitor_ip()
{
    /** @var \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $a */
    $a = df_o(\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress::class);
    return df_my_local() ? '92.243.166.8' : $a->getRemoteAddress();
}
Beispiel #13
0
 /**
  * 2016-05-19
  * 2016-05-20
  * Создавать коллекцию надо обязательно через Object Manager,
  * потому что родительский конструктор использует Dependency Injection.
  * @used-by df_countries()
  * @used-by \Df\Directory\Model\Country::cs()
  * @return self
  */
 public static function s()
 {
     static $r;
     return $r ? $r : ($r = df_o(__CLASS__));
 }
Beispiel #14
0
/**
 * 2016-04-05
 * @return AddressRegistry
 */
function df_address_registry()
{
    return df_o(AddressRegistry::class);
}
Beispiel #15
0
/**
 * 2016-05-06
 * https://mage2.pro/t/1543
 * @see df_invoice_send_email()
 * 2016-07-15
 * Usually, when you have received a payment confirmation from a payment system,
 * you should use @see df_order_send_email() instead of @see df_invoice_send_email()
 * What is the difference between InvoiceSender and OrderSender? https://mage2.pro/t/1872
 * @param O $order
 * @return void
 */
function df_order_send_email(O $order)
{
    /** @var OrderSender $sender */
    $sender = df_o(OrderSender::class);
    $sender->send($order);
    /** @var History|IHistory $history */
    $history = $order->addStatusHistoryComment(__('You have confirmed the order to the customer via email.'));
    $history->setIsCustomerNotified(true);
    $history->save();
}
Beispiel #16
0
/**
 * 2016-11-09
 * «How to get credentials from the HTTP basic access authentication?» https://mage2.pro/t/2257
 * Returns [$login, $password] pair.
 * @return string[]
 */
function df_http_credentials()
{
    /** @var Authentication $auth */
    $auth = df_o(Authentication::class);
    return $auth->getCredentials();
}
Beispiel #17
0
/**
 * 2015-10-05
 * @return \Magento\Framework\View\Page\Config
 */
function df_page()
{
    return df_o(\Magento\Framework\View\Page\Config::class);
}
Beispiel #18
0
/**
 * 2016-04-23
 * @return ImageHelper
 */
function df_catalog_image_h()
{
    return df_o(ImageHelper::class);
}
Beispiel #19
0
/**
 * 2015-09-29
 * @return \Magento\Framework\App\ResourceConnection
 */
function df_db_resource()
{
    return df_o(\Magento\Framework\App\ResourceConnection::class);
}
Beispiel #20
0
/**
 * 2016-04-05
 * @return Helper
 */
function df_directory_h()
{
    return df_o(Helper::class);
}
Beispiel #21
0
 /**
 * 2015-11-14
 * Очень красивое и неожиданное решение.
 * Оказывается, Magento 2 использует для настроечных полей
 * шаблон проектирования «Приспособленец»:
 * https://ru.wikipedia.org/wiki/Приспособленец_(шаблон_проектирования)
 * Поэтому настроечное поле является объектом-одиночкой,
 * и мы можем получить его из реестра.
 *
 * https://mage2.pro/t/212
 *
 * 1)
 * @see \Magento\Config\Model\Config\Structure\Element\Iterator\Field::__construct()
 		public function __construct(
 			\Magento\Config\Model\Config\Structure\Element\Group $groupFlyweight,
 			\Magento\Config\Model\Config\Structure\Element\Field $fieldFlyweight
 		) {
 			$this->_groupFlyweight = $groupFlyweight;
 			$this->_fieldFlyweight = $fieldFlyweight;
 		}
 * https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/app/code/Magento/Config/Model/Config/Structure/Element/Iterator/Field.php#L30
 *
 * 2)
 * @see \Magento\Config\Model\Config\Structure\Element\Group::__construct()
 		public function __construct(
 			(...)
 			\Magento\Config\Model\Config\Structure\Element\Iterator\Field $childrenIterator,
 			(...)
 		) {
 			parent::__construct($storeManager, $moduleManager, $childrenIterator);
 			(...)
 		}
 * https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/app/code/Magento/Config/Model/Config/Structure/Element/Group.php#L36
 *
 * 3)
 * @see \Magento\Config\Model\Config\Structure\Element\Iterator::current()
 		public function current()
 		{
 		return $this->_flyweight;
 		}
 * https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/app/code/Magento/Config/Model/Config/Structure/Element/Iterator.php#L68-L71
 *
 * @see \Magento\Config\Model\Config\Structure\Element\Iterator::next()
 		public function next()
 		{
 			next($this->_elements);
 			if (current($this->_elements)) {
 				$this->_initFlyweight(current($this->_elements));
 				if (!$this->current()->isVisible()) {
 					$this->next();
 				}
 			}
 		 }
 * https://github.com/magento/magento2/blob/2335247d4ae2dc1e0728ee73022b0a244ccd7f4c/app/code/Magento/Config/Model/Config/Structure/Element/Iterator.php#L78-L87
 *
 *
 * @return Field
 */
 private function field()
 {
     if (!isset($this->{__METHOD__})) {
         $this->{__METHOD__} = df_o(Field::class);
     }
     return $this->{__METHOD__};
 }
Beispiel #22
0
/**
 * 2016-05-06
 * @return Session|DfSession
 */
function df_checkout_session()
{
    return df_o(Session::class);
}
Beispiel #23
0
/**
 * https://mage2.pro/t/974
 * @return \Magento\Framework\Message\ManagerInterface|\Magento\Framework\Message\Manager
 */
function df_message_m()
{
    return df_o(\Magento\Framework\Message\ManagerInterface::class);
}
Beispiel #24
0
/**
 * 2016-07-13
 * @return TR
 */
function df_trans_r()
{
    return df_o(TR::class);
}
Beispiel #25
0
/**
 * @return \Magento\Store\Model\StoreManagerInterface|\Magento\Store\Model\StoreManager
 */
function df_store_m()
{
    static $r;
    return $r ? $r : ($r = df_o(\Magento\Store\Model\StoreManagerInterface::class));
}
Beispiel #26
0
/** @return IEncryptor|Encryptor */
function df_encryptor()
{
    return df_o(IEncryptor::class);
}
Beispiel #27
0
/**
 * 2016-07-18
 * @return IQuoteRepository|QuoteRepository
 */
function df_quote_r()
{
    return df_o(IQuoteRepository::class);
}
Beispiel #28
0
/**
 * 2016-05-06
 * @return ConfigInterface|Config|Compiled
 */
function df_om_config()
{
    return df_o(ConfigInterface::class);
}
Beispiel #29
0
/**
 * 2016-07-15
 * Usually, when you have received a payment confirmation from a payment system,
 * you should use @see df_order_send_email() instead of @see df_invoice_send_email()
 * What is the difference between InvoiceSender and OrderSender? https://mage2.pro/t/1872
 * @param Invoice $invoice
 * @return void
 */
function df_invoice_send_email(Invoice $invoice)
{
    /** @var InvoiceSender $sender */
    $sender = df_o(InvoiceSender::class);
    $sender->send($invoice);
}
Beispiel #30
0
/**
 * 2016-01-11
 * @return Helper
 */
function df_ie_helper()
{
    return df_o(Helper::class);
}