Skip to content

Commit

Permalink
Merge pull request #1 from helloextend/v1.1.0_SP
Browse files Browse the repository at this point in the history
This version will be 1.1.0 and contains shipping protection working with hyva checkout
  • Loading branch information
jm-extend authored May 22, 2024
2 parents b71b52e + b24463f commit c687da9
Show file tree
Hide file tree
Showing 18 changed files with 627 additions and 181 deletions.
153 changes: 153 additions & 0 deletions src/ViewModel/ShippingProtection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/*
* Copyright Extend (c) 2023. All rights reserved.
* See Extend-COPYING.txt for license details.
*/

namespace Extend\HyvaIntegration\ViewModel;

use Extend\Integration\Api\StoreIntegrationRepositoryInterface;
use Extend\Integration\Service\Extend;
use Extend\Integration\Service\Api\ActiveEnvironmentURLBuilder;
use Extend\Integration\Service\Api\Integration;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\ScopeInterface;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\Request\Http;

use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Model\QuoteFactory;
use Magento\Checkout\Model\CompositeConfigProvider;


class ShippingProtection implements
\Magento\Framework\View\Element\Block\ArgumentInterface
{
public const ENABLE_SHIPPING_PROTECTION = 'extend_plans/shipping_protection/enable';


/** @var StoreIntegrationRepositoryInterface */
private $storeIntegrationRepository;

/** @var StoreManagerInterface */
private $storeManager;

/** @var ScopeConfigInterface */
private $scopeConfig;

/** @var ActiveEnvironmentURLBuilder */
private $activeEnvironmentURLBuilder;

/** @var LoggerInterface */
private $logger;

/** @var Http */
private $request;

//JM
/** @var CartInterface */
private $cart;

/** @var CartRepositoryInterface */
private $cartRepository;

/** @var QuoteFactory */
private $quote;

/** @var CompositeConfigProvider */
protected $configProvider;




/**
* ShippingProtection constructor
*
* @param StoreIntegrationRepositoryInterface $storeIntegrationRepository
* @param StoreManagerInterface $storeManager
* @param ScopeConfigInterface $scopeConfig
* @param ActiveEnvironmentURLBuilder $activeEnvironmentURLBuilder
* @param LoggerInterface $logger
* @param Http $request
* //JM
* @param CartInterface $cart
* @param CartRepositoryInterface $cartRepository
* @param QuoteFactory $quote
* @param CompositeConfigProvider $configProvider
*
*/
public function __construct(
StoreIntegrationRepositoryInterface $storeIntegrationRepository,
StoreManagerInterface $storeManager,
ScopeConfigInterface $scopeConfig,
ActiveEnvironmentURLBuilder $activeEnvironmentURLBuilder,
LoggerInterface $logger,
Http $request,
//JM
CartInterface $cart,
CartRepositoryInterface $cartRepository,
QuoteFactory $quote,
CompositeConfigProvider $configProvider

) {
$this->storeIntegrationRepository = $storeIntegrationRepository;
$this->storeManager = $storeManager;
$this->scopeConfig = $scopeConfig;
$this->activeEnvironmentURLBuilder = $activeEnvironmentURLBuilder;
$this->logger = $logger;
$this->request = $request;
//JM
$this->cart = $cart;
$this->cartRepository = $cartRepository;
$this->quote = $quote;
$this->configProvider = $configProvider;
}


/**
* Determine if Extend Shipping Protection is currently enabled
*
* @return bool
*/
public function isExtendShippingProtectionEnabled(): bool
{
return $this->getScopedConfigValue(Extend::ENABLE_SHIPPING_PROTECTION) === '1';
}


/**
* Get Scoped Config Value
*
* @param string $configPath
* @return string
*/
private function getScopedConfigValue(string $configPath): string
{
$scopeCode = $this->storeManager->getStore()->getCode();
$scopeType = ScopeInterface::SCOPE_STORES;
return $this->scopeConfig->getValue($configPath, $scopeType, $scopeCode) ?: '';
}


/**
* Get quote grand total
*
* @param int $quoteId
* @return float|null
*/
public function getTotals($quoteId)
{
$quote = $this->getQuoteById($quoteId);
return $quote ? $quote->getGrandTotal() : null;
}


public function getCheckoutConfig(): array
{
return $this->configProvider->getConfig();
}


}
17 changes: 17 additions & 0 deletions src/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0"?>
<!--
~ Copyright Extend (c) 2022. All rights reserved.
~ See Extend-COPYING.txt for license details.
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="sales" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="totals_sort" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1">
<field id="shipping_protection" translate="label" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" canRestore="1">
<label>Shipping Protection</label>
<validate>required-number validate-number</validate>
</field>
</group>
</section>
</system>
</config>
21 changes: 0 additions & 21 deletions src/view/frontend/layout/catalog_category_view.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!--
~ Copyright Extend (c) 2023. All rights reserved.
~ See Extend-COPYING.txt for license details.
<referenceContainer name="product.info.form.content">
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<!--
~ Copyright Extend (c) 2023. All rights reserved.
~ See Extend-COPYING.txt for license details.
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="product.info.form">
<block class="Magento\GroupedProduct\Block\Product\View\Type\Grouped"
ifconfig="extend/integration/enable" after="-"
name="extend.product.view.type.grouped.product-protection-offer"
template="Extend_HyvaIntegration::catalog/product/view/type/grouped/product-protection-offer.phtml">
<arguments>
<argument name="viewModel" xsi:type="object">Extend\Integration\ViewModel\EnvironmentAndExtendStoreUuid</argument>
</arguments>
</block>
</referenceContainer>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!--
~ Copyright Extend (c) 2023. All rights reserved.
~ See Extend-COPYING.txt for license details.
<referenceContainer name="product.info.form.content">
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
Expand Down
46 changes: 46 additions & 0 deletions src/view/frontend/layout/hyva_checkout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<!--
~ Copyright Extend (c) 2022. All rights reserved.
~ See Extend-COPYING.txt for license details.
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Extend_HyvaIntegration/checkout/summary/shipping-protection-offer</item>
</item>
<item name="component" xsi:type="string">Extend_HyvaIntegration/checkout/summary/shipping-protection-offer</item>
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<!-- <referenceContainer name="content">-->
<!-- <block name="extend-environment-store-uuid" template="Extend_HyvaIntegration::checkout/sp-quote-config.phtml">-->
<!-- <arguments>-->
<!-- <argument name="viewModel" xsi:type="object">Extend\Integration\ViewModel\EnvironmentAndExtendStoreUuid</argument>-->
<!-- </arguments>-->
<!-- </block>-->
<!-- </referenceContainer>-->
<referenceBlock name="checkout.shipping.methods.after">
<block name="shipping-additional" template="Extend_HyvaIntegration::checkout/summary/shipping-protection-offer.phtml" after="-">
<arguments>
<argument name="viewModel" xsi:type="object">Extend\HyvaIntegration\ViewModel\ShippingProtection</argument>
</arguments>
</block>
</referenceBlock>


<referenceBlock name="price-summary.total-segments">
<block name="price-summary.total-segment.shipping_protection"
as="shipping_protection"
template="Extend_HyvaIntegration::checkout/summary/shipping-protection.phtml"
after="price-summary.total-segment.subtotal"
>
<arguments>
<argument name="viewModel" xsi:type="object">Extend\HyvaIntegration\ViewModel\ShippingProtection</argument>
</arguments>
</block>
</referenceBlock>

<!-- <move element="price-summary.total-segment.shipping_protection" destination="price-summary.total-segments" before="price-summary.total-segment.shipping"/>-->


</body>
</page>
60 changes: 2 additions & 58 deletions src/view/frontend/layout/hyva_checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!--
~ Copyright Extend (c) 2022. All rights reserved.
~ See Extend-COPYING.txt for license details.
-->
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
Expand All @@ -12,62 +12,6 @@
</arguments>
</block>
</referenceContainer>
<referenceBlock name="checkout.root">
<arguments>
<argument name="jsLayout" xsi:type="array">
<item name="components" xsi:type="array">
<item name="checkout" xsi:type="array">
<item name="children" xsi:type="array">
<item name="steps" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shipping-step" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAddress" xsi:type="array">
<item name="children" xsi:type="array">
<item name="shippingAdditional" xsi:type="array">
<item name="component" xsi:type="string">uiComponent</item>
<item name="displayArea" xsi:type="string">shippingAdditional</item>
<item name="children" xsi:type="array">
<item name="additional_block" xsi:type="array">
<item name="component" xsi:type="string">Extend_Integration/js/view/checkout/summary/shipping-protection-offer</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
<item name="sidebar" xsi:type="array">
<item name="children" xsi:type="array">
<item name="summary" xsi:type="array">
<item name="children" xsi:type="array">
<item name="totals" xsi:type="array">
<item name="children" xsi:type="array">
<!-- Start of the main content that needs to be added-->
<item name="shipping_protection" xsi:type="array">
<!-- The path to our js file-->
<item name="component" xsi:type="string">Extend_Integration/js/view/checkout/summary/shipping-protection</item>
<item name="sortOrder" xsi:type="string">24</item>
<item name="config" xsi:type="array">
<item name="template" xsi:type="string">Extend_Integration/checkout/summary/shipping-protection</item>
<!-- Show custom shipping protection on order summary-->
<item name="title" xsi:type="string" translate="true">Shipping Protection</item>
</item>
</item>
</item>
</item>
<!-- End-->
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>

</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
/** @var Magento\Framework\Escaper $escaper */
/** @var Magento\Catalog\Block\Product\View $block */

$stringUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration/js/utils/string-utils.js'));
$cartUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration/js/utils/cart-utils.js'));
$stringUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration::js/utils/string-utils.js'));
$cartUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration::js/utils/cart-utils.js'));

/** @var \Magento\Quote\Model\Quote\Item $_item */
$item = $block->getItem();
Expand Down
4 changes: 2 additions & 2 deletions src/view/frontend/templates/cart/minicart-simple-offer.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/** @var Magento\Framework\Escaper $escaper */
/** @var Magento\Catalog\Block\Product\View $block */

$stringUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration/js/utils/string-utils.js'));
$cartUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration/js/utils/cart-utils.js'));
$stringUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration::js/utils/string-utils.js'));
$cartUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration::js/utils/cart-utils.js'));
$viewModel = $block->getData('viewModel');
$extendStoreUuid = $viewModel->getExtendStoreUuid();
$activeEnvironment = $viewModel->getActiveEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/** @var Magento\Catalog\Block\Product\View $block */

$viewModel = $block->getData('viewModel');
$cartUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration/js/utils/cart-utils.js'));
$cartUtils = $escaper->escapeJs($block->getViewFileUrl('Extend_HyvaIntegration::js/utils/cart-utils.js'));

function guidv4($data = null) {
// Generate 16 bytes (128 bits) of random data or use the data passed into the function.
Expand Down
Loading

0 comments on commit c687da9

Please sign in to comment.