Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Smile-SA/magento2-module-store-de…
Browse files Browse the repository at this point in the history
…livery

* 'master' of github.com:Smile-SA/magento2-module-store-delivery:
  Create README.md
  Fix Smile-SA#9 - Fix observer when store delivery method is disabled
  Add issue template
  Rename Carrier Model to prevent magento failure when exploding on underscores.
  Fix Temando erratic observer.
  Remove page layout update
  Remove PHP dependency. Let Magento handle it.
  • Loading branch information
marcatos committed Nov 23, 2018
2 parents bf3f6d4 + 52a8dc8 commit cfb7205
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 11 deletions.
32 changes: 32 additions & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--- Provide a general summary of the issue in the Title above -->

### Preconditions
<!--- Please Provide detailed informations about the environment you use -->

<!-- Magento Version : Are you using Magento CE or EE ? Which version of Magento are you using exactly ? -->
Magento Version :

<!-- Module Store Delivery Version : Which exact version of Module Store Delivery are you using ? -->
Module Store Delivery Version :

<!-- Magento Environment : are you in Developer or Production mode ? -->
Environment :

<!-- Third party modules : are you using any third party modules ? If yes, please attach the list -->
Third party modules :

### Steps to reproduce
<!--- Provide a set of unambiguous steps to reproduce this bug. You can also include pieces of code if you think it's relevant -->
1.
2.
3.

### Expected result
<!--- Tell us what should happen -->
1.

### Actual result
<!--- Tell us what happens instead -->
1. [Screenshot, logs]

<!--- (This may be platform independent comment) -->
2 changes: 1 addition & 1 deletion Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Carrier extends AbstractCarrier implements CarrierInterface
/**
* Constant for method code
*/
const METHOD_CODE = 'smile_store_delivery';
const METHOD_CODE = 'smilestoredelivery';

/**
* @var string
Expand Down
2 changes: 1 addition & 1 deletion Observer/QuoteSubmit.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($shippingMethod) {
$methodCode = \Smile\StoreDelivery\Model\Carrier::METHOD_CODE;
$carrier = $this->carrierFactory->getIfActive($methodCode);
if (is_object($carrier) && $shippingMethod === sprintf('%s_%s', $methodCode, $carrier->getCarrierCode())) {
if ($carrier && $shippingMethod === sprintf('%s_%s', $methodCode, $carrier->getCarrierCode())) {
$billingAddress = $quote->getBillingAddress();

if (!$shippingAddress->getFirstname()) {
Expand Down
55 changes: 55 additions & 0 deletions Plugin/Temando/SaveCheckoutFieldsObserverPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* DISCLAIMER
* Do not edit or add to this file if you wish to upgrade this module to newer
* versions in the future.
*
* @category Smile
* @package Smile\StoreDelivery
* @author Romain Ruaud <[email protected]>
* @copyright 2018 Smile
* @license Open Software License ("OSL") v. 3.0
*/
namespace Smile\StoreDelivery\Plugin\Temando;

/**
* This observer is here to prevent erratic behavior of Temando module. @see https://github.com/magento/magento2/issues/12921
*
* @category Smile
* @package Smile\StoreDelivery
* @author Romain Ruaud <[email protected]>
*/
class SaveCheckoutFieldsObserverPlugin
{
/**
* Better check than what is done in the Temando Observer which is thinking he is the only one adding extension
* attributes to the Quote address.
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param \Temando\Shipping\Observer\SaveCheckoutFieldsObserver $subject Base Temando Observer
* @param \Closure $proceed execute() method of Temando Observer
* @param \Magento\Framework\Event\Observer $observer Magento Event Observer
*/
public function aroundExecute(
\Temando\Shipping\Observer\SaveCheckoutFieldsObserver $subject,
\Closure $proceed,
\Magento\Framework\Event\Observer $observer
) {
/** @var \Magento\Quote\Api\Data\AddressInterface|\Magento\Quote\Model\Quote\Address $quoteAddress */
$quoteAddress = $observer->getData('quote_address');
if ($quoteAddress->getAddressType() !== \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING) {
return;
}

if (!$quoteAddress->getExtensionAttributes()) {
return;
}

if (!$quoteAddress->getExtensionAttributes()->getCheckoutFields()) {
return;
}

$proceed($observer);
}
}
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
### Smile Store Delivery

This module is a plugin for [ElasticSuite](https://github.com/Smile-SA/elasticsuite).

This module add the ability to be delivered in store. Store delivery is a shipping method.

### Requirements

The module requires :

- [Store Locator](https://github.com/Smile-SA/magento2-module-store-locator) > 1.2.*

### How to use

1. Install the module via Composer :

``` composer require smile/module-store-delivery ```

2. Enable it

``` bin/magento module:enable Smile_StoreDelivery ```

3. Install the module and rebuild the DI cache

``` bin/magento setup:upgrade ```

### How to configure

> Stores > Configuration > Sales > Shipping Methods > Store Delivery
Field | Type
-----------------------------|----------------------------------------------
Enabled | Yes/No
Title | Varchar
Method Name | Varchar
Price | Decimal
Calculate Handling Fee | Fixed/Percent
Handling Fee | Varchar
Displayed Error Message | Text
Ship to Applicable Countries | All Allowed Countries/Specific Countries
Ship to Specific Countries | Varchar (Multiselect countries)
Sort Order | Integer
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
}
],
"require": {
"php": "~5.5.0|~5.6.0|~7.0.0",
"magento/framework": "*",
"magento/module-store": "*",
"magento/module-checkout": "*",
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="carriers" translate="label" type="text" sortOrder="320" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="smile_store_delivery" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">
<group id="smilestoredelivery" translate="label" type="text" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1">

<label>Store Delivery</label>

Expand Down
4 changes: 2 additions & 2 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<carriers>
<smile_store_delivery>
<smilestoredelivery>
<active>1</active>
<sallowspecific>0</sallowspecific>
<model>Smile\StoreDelivery\Model\Carrier</model>
Expand All @@ -27,7 +27,7 @@
<type>I</type>
<specificerrmsg>This shipping method is not available. To use this shipping method, please contact us.
</specificerrmsg>
</smile_store_delivery>
</smilestoredelivery>
</carriers>
</default>
</config>
Expand Down
6 changes: 5 additions & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
<plugin name="store_delivery_estimate_rates_by_address" type="Smile\StoreDelivery\Plugin\Quote\Api\ShippingMethodManagementPlugin"/>
</type>


<type name="Magento\Quote\Model\Quote\Address\ToOrderAddress">
<plugin name="gift_registry_quote_address_to_order_address" type="Smile\StoreDelivery\Plugin\Quote\Model\ConvertQuoteAddressToOrderAddress"/>
</type>

<!-- Fix issue with Temando module : https://github.com/magento/magento2/issues/12921 -->
<type name="\Temando\Shipping\Observer\SaveCheckoutFieldsObserver">
<plugin name="fix_temando_shipping_observer" type="Smile\StoreDelivery\Plugin\Temando\SaveCheckoutFieldsObserverPlugin"/>
</type>
</config>
2 changes: 1 addition & 1 deletion view/frontend/layout/checkout_index_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license Open Software License ("OSL") v. 3.0
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="checkout.root">
<arguments>
Expand Down
4 changes: 2 additions & 2 deletions view/frontend/web/js/view/checkout/shipping/store-delivery.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ define([
return Component.extend({
defaults: {
template: 'Smile_StoreDelivery/checkout/shipping/store-delivery',
methodCode: 'smile_store_delivery',
carrierCode: 'smile_store_delivery',
methodCode: 'smilestoredelivery',
carrierCode: 'smilestoredelivery',
retailerId : retailer().entity_id || 0,
init: true
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ define(
// Register store delivery address provider.
// Always add it, if the carrier is available.
// This will by default add a new "empty" address allowing the customer to select a shop.
if (window.checkoutConfig.activeCarriers.indexOf('smile_store_delivery') !== -1) {
if (window.checkoutConfig.activeCarriers.indexOf('smilestoredelivery') !== -1) {
if (addressList().length === 0) {
addressList.push(new customerAddress([]));
}
Expand Down

0 comments on commit cfb7205

Please sign in to comment.