/** * {@inheritdoc} */ public function getConfig() { $isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE); if ($isAgreementsEnabled && count($this->checkoutAgreementsRepository->getList()) > 0) { return ['checkoutAgreementsEnabled' => true]; } return []; }
/** * Agreements list getter * @return array */ public function toOptionArray() { $agreements = [['value' => 0, 'label' => __('No')]]; foreach ($this->checkoutAgreementsRepository->getList() as $agreement) { $agreements[] = ['value' => $agreement->getId(), 'label' => $agreement->getName()]; } return $agreements; }
/** * {@inheritdoc} */ public function process($jsLayout) { $agreementConfiguration = []; $agreementsList = $this->checkoutAgreementsRepository->getList(); foreach ($agreementsList as $agreement) { $agreementConfiguration[] = ['content' => $agreement->getIsHtml() ? $agreement->getContent() : nl2br($this->escaper->escapeHtml($agreement->getContent())), 'height' => $agreement->getContentHeight(), 'checkboxText' => $agreement->getCheckboxText()]; } $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children']['before-place-order']['children']['checkout-agreements-modal']['config']['agreementConfiguration'] = $agreementConfiguration; return $jsLayout; }
/** * Returns agreements config * * @return array */ protected function getAgreementsConfig() { $agreementConfiguration = []; $isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE); $agreementsList = $this->checkoutAgreementsRepository->getList(); $agreementConfiguration['isEnabled'] = (bool) ($isAgreementsEnabled && count($agreementsList) > 0); foreach ($agreementsList as $agreement) { $agreementConfiguration['agreements'][] = ['content' => $agreement->getIsHtml() ? $agreement->getContent() : nl2br($this->escaper->escapeHtml($agreement->getContent())), 'checkboxText' => $agreement->getCheckboxText(), 'mode' => $agreement->getMode(), 'agreementId' => $agreement->getAgreementId()]; } return $agreementConfiguration; }
/** * {@inheritdoc} */ public function process($jsLayout) { $form = []; $agreementsList = $this->checkoutAgreementsRepository->getList(); foreach ($agreementsList as $agreement) { $name = $agreement->getAgreementId(); $form[$name] = ['component' => 'Magento_Ui/js/form/element/abstract', 'config' => ['customScope' => 'checkoutAgreements', 'customEntry' => 'checkoutAgreements.' . $name, 'template' => 'Magento_CheckoutAgreements/form/element/agreement'], 'agreementConfiguration' => ['content' => $agreement->getIsHtml() ? $agreement->getContent() : nl2br($this->escaper->escapeHtml($agreement->getContent())), 'height' => $agreement->getContentHeight(), 'checkboxText' => $agreement->getCheckboxText()], 'dataScope' => $name, 'provider' => 'checkoutProvider', 'validation' => ['checked' => true], 'customEntry' => null, 'visible' => true]; } $result['components']['checkout']['children']['steps']['children']['review']['children']['beforePlaceOrder']['children']['checkoutAgreements']['children'] = $form; return array_merge_recursive($jsLayout, $result); }
/** * Selected agreement getter * @return \Magento\CheckoutAgreements\Api\CheckoutAgreementsRepositoryInterface|bool */ public function getSelected() { if ($this->scopeConfig->isSetFlag('checkout/options/enable_agreements', ScopeInterface::SCOPE_STORE)) { $id = $this->getSelectedId(); if ($id > 0) { try { $selected = $this->checkoutAgreementsRepository->get($id); if ($selected->getIsActive()) { return $selected; } else { return false; } } catch (NoSuchEntityException $e) { return false; } } } return false; }
/** * Verify if agreement validation needed * @return bool */ protected function isAgreementEnabled() { $isAgreementsEnabled = $this->scopeConfiguration->isSetFlag(AgreementsProvider::PATH_ENABLED, ScopeInterface::SCOPE_STORE); $agreementsList = $isAgreementsEnabled ? $this->checkoutAgreementsRepository->getList() : []; return (bool) ($isAgreementsEnabled && count($agreementsList) > 0); }