Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIPPS-451: Add config for virtual products and process it. #180

Open
wants to merge 1 commit into
base: VIPPS-449
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Block/Express/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/

namespace Vipps\Payment\Block\Express;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template;
use Magento\Framework\View\Asset\Repository;
use Magento\Framework\View\Element\AbstractBlock;
Expand Down Expand Up @@ -67,16 +70,23 @@ class Button extends Template implements ShortcutInterface
*/
public function __construct(
Template\Context $context,
Random $mathRandom,
ConfigInterface $config,
array $data = []
Random $mathRandom,
ConfigInterface $config,
Registry $registry,
array $data = []
) {
$this->config = $config;
$this->assetRepo = $context->getAssetRepository();
$this->mathRandom = $mathRandom;
$this->registry = $registry;
parent::__construct($context, $data);
}

private function getProduct(): ?ProductInterface
{
return $this->registry->registry('product');
}

/**
* Disable block output if button visibility is turned off.
*
Expand All @@ -96,9 +106,22 @@ protected function _toHtml() //@codingStandardsIgnoreLine
return '';
}

if ($this->getIsInCatalogProduct()
&& !$this->config->getValue('virtual_products_display')
&& $this->getProduct()
&& $this->getProduct()->getTypeId() === \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
) {
return '';
}

return parent::_toHtml();
}

public function getVirtualProductDisplay(): bool
{
return (bool)$this->config->getValue('virtual_products_display');
}

/**
* {@inheritdoc}
*
Expand Down
5 changes: 5 additions & 0 deletions etc/adminhtml/system/express_checkout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
</field>
<group id="settings_checkout" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="50">
<label>Advanced Settings</label>
<field id="show_for_virtual" translate="label" type="select" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="10">
<label>Show On Virtual Products</label>
<config_path>payment/vipps/virtual_products_display</config_path>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="checkout_cart_display" translate="label" type="select" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="10">
<label>Display on Shopping Cart</label>
<config_path>payment/vipps/checkout_cart_display</config_path>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<partial_void_sender_email>sales</partial_void_sender_email>
<partial_void_email_template>payment_vipps_partial_void_email_template</partial_void_email_template>
<partial_void_mail_message><![CDATA[Just want to inform you that some items from your order was canceled. Unfortunately Vipps don't support partial void yet, but no worries, all your money will get back after authorization will be canceled by your bank automatically.]]></partial_void_mail_message>
<virtual_products_display>0</virtual_products_display>
</vipps>
</payment>
</default>
Expand Down
1 change: 1 addition & 0 deletions etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<module name="Magento_Sales" />
<module name="Magento_Payment" />
<module name="Magento_Checkout" />
<module name="Magento_Catalog" />
</sequence>
</module>
</config>
8 changes: 3 additions & 5 deletions view/frontend/templates/button.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
<?php
/** @var $block \Vipps\Payment\Block\Express\Button */
$size = $block->getData('size');
$isInCatalogProduct = false;
if ($block->getIsInCatalogProduct()) {
$isInCatalogProduct = $block->getIsInCatalogProduct();
}
$isInCatalogProduct = $block->getIsInCatalogProduct() ?: false;
$shortcutHtmlId = $block->escapeHtml($block->getShortcutHtmlId());
?>

Expand All @@ -31,7 +28,8 @@ $shortcutHtmlId = $block->escapeHtml($block->getShortcutHtmlId());
data-mage-init='{
"Vipps_Payment/js/view/vipps-express-checkout": {
"isCatalogProduct": "<?= (bool)$isInCatalogProduct //@codingStandardsIgnoreLine ?>",
"shortcutContainerClass": ".<?= $shortcutHtmlId //@codingStandardsIgnoreLine ?>"
"shortcutContainerClass": ".<?= $shortcutHtmlId //@codingStandardsIgnoreLine ?>",
"virtualProductDisplay": "<?= $block->getVirtualProductDisplay() //@codingStandardsIgnoreLine ?>"
}
}'>
<svg width="253px" height="48px" viewBox="0 0 253 48" role="img"
Expand Down
7 changes: 3 additions & 4 deletions view/frontend/web/js/view/vipps-express-checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
* IN THE SOFTWARE.
*/
define([
'jquery',
'jquery/ui',
'mage/mage'
], function ($) {
'jquery',
'mage/mage',
], function ($, mage, storage, Element) {
'use strict';

$.widget('mage.vippsCheckout', {
Expand Down