本文整理汇总了PHP中Magento\Framework\Event\Observer::getDataByKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Observer::getDataByKey方法的具体用法?PHP Observer::getDataByKey怎么用?PHP Observer::getDataByKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Event\Observer
的用法示例。
在下文中一共展示了Observer::getDataByKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Create payment vault record
*
* @param Observer $observer
* @return $this
*/
public function execute(Observer $observer)
{
/** @var OrderPaymentInterface $payment */
$payment = $observer->getDataByKey(self::PAYMENT_OBJECT_DATA_KEY);
$extensionAttributes = $payment->getExtensionAttributes();
$paymentToken = $this->getPaymentToken($extensionAttributes);
if ($paymentToken === null) {
return $this;
}
if ($paymentToken->getEntityId() !== null) {
$this->paymentTokenManagement->addLinkToOrderPayment($paymentToken->getEntityId(), $payment->getEntityId());
return $this;
}
$order = $payment->getOrder();
$paymentToken->setCustomerId($order->getCustomerId());
$paymentToken->setIsActive(true);
$paymentToken->setPaymentMethodCode($payment->getMethod());
$additionalInformation = $payment->getAdditionalInformation();
if (isset($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE])) {
$paymentToken->setIsVisible((bool) (int) $additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE]);
}
$paymentToken->setPublicHash($this->generatePublicHash($paymentToken));
$this->paymentTokenManagement->saveTokenWithPaymentLink($paymentToken, $payment);
$extensionAttributes->setVaultPaymentToken($paymentToken);
return $this;
}
示例2: execute
/**
* Create payment vault record
*
* @param Observer $observer
* @return $this
*/
public function execute(Observer $observer)
{
/** @var OrderPaymentInterface $payment */
$payment = $observer->getDataByKey(self::PAYMENT_OBJECT_DATA_KEY);
$extensionAttributes = $payment->getExtensionAttributes();
$paymentToken = $this->getPaymentToken($extensionAttributes);
// Save only new tokens that has been set during first order placement
if ($paymentToken === null || $paymentToken->getEntityId() > 0) {
return $this;
}
$paymentToken->setPublicHash($this->generatePublicHash($paymentToken));
$paymentToken->setIsActive(true);
$additionalInformation = $payment->getAdditionalInformation();
if (isset($additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE])) {
$paymentToken->setIsVisible((bool) (int) $additionalInformation[VaultConfigProvider::IS_ACTIVE_CODE]);
}
$this->paymentTokenManagement->saveTokenWithPaymentLink($paymentToken, $payment);
$extensionAttributes->setVaultPaymentToken($paymentToken);
return $this;
}