Giter Site home page Giter Site logo

magento2-module-gift-sales-rule's Introduction

Gift Sales Rule Build Status

What is magento2-module-gift-sales-rule Magento 2 Module?

This module provides 2 new actions to Magento cart price rule feature to :

  • offer gift product(s) to customer based on native conditions
  • offer gift product(s) to customer each time a threshold is reached (every 30$ in cart for example)

For each cart price rule, administrator can define the number of gift products authorized and use a set of conditions to define the gift product list. On the frontend side, when the rule is applied, the customer can choose between a list of products the one(s) he prefers and add them to his cart.

Gift products type can be:

  • simple product
  • configurable product

Who is developing this module ?

Smile

This module is built by Smile.

Smile is the European leader of Open Source and also a four-times Europe Partner of the the Year (2010-2014), two-times Spirit of Excellence (2015-2016), Global Elite Partner (2017-now), and Regional Commercial Partner (2018) awarded by Magento.

Our multidisciplinary team brings together experts in technology, innovation, and new applications.

Together we explore, invent, and test technologies of the future, to better serve our clients.

Main Features

  • Configure cart price rules to select gift products To offer product

  • Configure cart price rules to select gift products and the price range To offer product per price range

  • Display gift product popin Gift popin

  • Display added gift product in cart Gift cart

Documentation

Documentation is available here.

Standards & Code Quality

Built on top of Magento2, our module respects all its prerequisites and code quality rules.

You can also find our PHPCS Standards and PHPMD rulesets in the module directory.

The module is also continuously tested on :

Tools Results
Travis Build Status

magento2-module-gift-sales-rule's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magento2-module-gift-sales-rule's Issues

Issue with Magento Enterprise and the staging module

Hi,

In Magento EE 2.3.X (and probably in 2.4.X), in the following case :
A salesrule with a rule_id different (for example 4) of the row_id (for example 1)
In the table smile_gift_salesrule, no row with a rule_id 4

In the table smile_gift_salesrule, the rule_id is linked to the row_id of salesrule. But in the code, we always give to the repository the rule_id of salesrule.
In most of case, it will work, because it exists often a row in salesrule which has the same rule_id and row_id.
But in rare case, it does not exist and cause a fatal error.
The solution is in CE, give the rule_id to the gift salesrule repository, in EE, give the row_id.

Plugin class Magento\Multishipping\Plugin\DisableMultishippingMode doesn't exist

Hello, I'm having this problem:

php -d memory_limit=8000M bin/magento setup:di:compile;
Compilation was started.
Interceptors generation... 4/7 [================>-----------] 57% 14 secs 241.0 MiB
In PluginList.php line 182:

Plugin class Magento\Multishipping\Plugin\DisableMultishippingMode doesn't exist


Magento version 2.3.2

Do you know how to solve this?

Thanks

Add an event to be able to add data into gift sales rule cache

Hi,

we need actually to add some data from the Magento rule model (vendor/smile/module-gift-sales-rule/Helper/Cache.php l124) before it is saved into cache.
Maybe send an event before saving could be good to be able to customize data ?

Thanks,
Pierre

Apply only with reloading page

Thanks for this module.
However I have a problem : the gift proposal appears only after reloading the page.
Am I the only one with this feat ?

Problem with the price of a single gift in the order summary

I have a problem with this module. I want to modify it so that the price for one gift is 0.01 instead of 0.00, and that you can easily remove this gift from the cart if you don't want it. I had an idea to make the CollectGiftRule instead of the sales_quote_collect_totals_after event work on the sales_quote_save_after event (and calling the collectTotals() method in the middle of the observer), but then in the order summary in the cart it still includes the price of 0.00 for one gift instead of 0.01 (the amount in this particular gift item in the cart it is displayed correctly (0,01), only in the summing up it does not add up correctly, it does not add 0.01 to the total sum). After proceeding further, the price is already correct.

Free product based on product attribute condition not working

Precondition:

  • Magneto 2.3.4
  • PHP 7.3
  • Nginx 1.16
  • Smile Gift Sales Rule module version: 1.0.1

Step to Reproduce:

  • Create new rule to add free gift product without coupon code
  • Add condition like "SKU is xxxxxxx"
  • Action like "SKU is xxxxxxx"
  • Frontend - Add to cart same product as applied condition and rule applied successfully
  • Frontend - Add different product than mentioned in condition and still free product displayed in cart
  • Issue is with all product attributes like "SKU, category, Size, Special price"etc.

Expected Result:

  • Free gift product should be in cart only for product applied in condition

Actual Result:

  • Free gift product in cart even if wrong product add in cart

Screen Shot 2021-05-26 at 16 24 47

Free gift stays in saved carts even when the promo rule with it is inactive

Pre-conditions

Magento ver. 2.4.3-p1

We have a promo rule with free gift running from Feb 11 to Feb 15

During this period a visitor added number of products to the cart and became rightly eligible for a gift, so the gift appears in the cart

That is fine

The client hasn't finalized purchase that time.

Then he returned to the website Feb 23, when the rule with free gift wasn't active in the same browser.

Actual behaviour

Free gift was still in his cart, he finalized order and got this free gift

Expected behaviour

Free should not be gift not in the cart, because the rule that add it isn't active anymore

the rule 'Offer product per range' is not well applied when MSRP is disabled

Hello,

Steps to reproduce :
Disable the configuration : sales/msrp/enabled (enabled by default with sample data)
Add a product (at 20€) to cart
Apply a salesrule 'Offer product per range' with one product per 15€
The popin offers one product -> OK
change the quantity to 2 of the first product in the checkout cart page.
The popins still offers only one product instead of two.

The reason :
magento/vendor/magento/module-msrp/Block/Total.php l51 : there is a collectTotals when the configuration is enabled. It allows to the popin to offer the right number of offered products.
If disabled, you need to refresh the page to have the right number of offered products.

No entity with objectId = 77

Hello,
since an update of php (php 7.3 now) I can't use the module anymore.
Got this error when the rule is 'ok' (No entity with objectId = 77) :
Magento 2.3.3 or 2.3.6-p1 (same error)

1 exception(s):
Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Aucune entité avec objectId = 77

Exception #0 (Magento\Framework\Exception\NoSuchEntityException): Aucune entité avec objectId = 77
<pre>#1 Smile\GiftSalesRule\Model\GiftRuleRepository->getById(77) called at [vendor/smile/module-gift-sales-rule/Model/GiftRuleRepository.php:133]
#2 Smile\GiftSalesRule\Model\GiftRuleRepository->getByRule(&Magento\SalesRule\Model\Rule#000000006166a7f0000000007c4be91d#) called at [vendor/smile/module-gift-sales-rule/Model/Rule/Action/Discount/OfferProduct.php:103]
....

Could you help please ?

The maximum number product changes for 'OfferProductPerPriceRange' rules when an order is saved

Hi,

The maximum number product changes for 'OfferProductPerPriceRange' rules when an order is saved.

To reproduce:
apply a sales rule of type 'OfferProductPerPriceRange' (example: max number product = 1, price range = 10).
Have a cart with a subtotal >= 40.
Select 4 free products.
Make the order.
Check in back-office the sales rule -> The maximum number product is updated to 4.

The maximum number product should not change after an order.
Thanks,
Pierre

Feature Request: gift promo step

Hi,

First of all, thanks for sharing the module with the community. I would like to ask for the following feature request:

  • Current functionality: we can create a promorule that, when a product is found in the cart, we can add a gift product.
  • We would like this promo to be applied as many times as it is matched. I mean:
    -- Promo is: if you have 1 unit of SKU AAAA in your cart, we offer you 1 unit of SKU BBBB
    -- If you have 2 units of SKU AAAA, we offer you 2 units of SKU BBB
    -- If you have 3 units AAA ... we offer 3 units BBB
    -- ...

Is this possible with the current module with only one rule?

Thanks

SalesRule legacy REST Api broken

I just noticed that when I process a REST Api query to rest/V1/salesRules/:ruleId I obtain the following result :

{
    "message": "Class \\Smile\\GiftSalesRule\\Api\\Data\\GiftRuleInterface[] does not exist",
    "code": -1,
    "trace": "#0 /var/www/magento/src/vendor/magento/framework/Reflection/MethodsMap.php(155): ReflectionClass->__construct('\\\\Smile\\\\GiftSale...')\n#1 /var/www/magento/src/vendor/magento/framework/Reflection/MethodsMap.php(106): Magento\\Framework\\Reflection\\MethodsMap->getMethodMapViaReflection('\\\\Smile\\\\GiftSale...')\n#2 /var/www/magento/src/vendor/magento/framework/Reflection/DataObjectProcessor.php(75): Magento\\Framework\\Reflection\\MethodsMap->getMethodsMap('\\\\Smile\\\\GiftSale...')\n#3 /var/www/magento/src/generated/code/Magento/Framework/Reflection/DataObjectProcessor/Proxy.php(95): Magento\\Framework\\Reflection\\DataObjectProcessor->buildOutputDataArray(Object(Smile\\GiftSalesRule\\Model\\GiftRule), '\\\\Smile\\\\GiftSale...')\n#4 /var/www/magento/src/vendor/magento/framework/Reflection/ExtensionAttributesProcessor.php(118): Magento\\Framework\\Reflection\\DataObjectProcessor\\Proxy->buildOutputDataArray(Object(Smile\\GiftSalesRule\\Model\\GiftRule), '\\\\Smile\\\\GiftSale...')\n#5 /var/www/magento/src/vendor/magento/framework/Reflection/DataObjectProcessor.php(101): Magento\\Framework\\Reflection\\ExtensionAttributesProcessor->buildOutputDataArray(Object(Magento\\SalesRule\\Api\\Data\\RuleExtension), '\\\\Magento\\\\SalesR...')\n#6 /var/www/magento/src/vendor/magento/framework/Webapi/ServiceOutputProcessor.php(109): Magento\\Framework\\Reflection\\DataObjectProcessor->buildOutputDataArray(Object(Magento\\SalesRule\\Model\\Data\\Rule), '\\\\Magento\\\\SalesR...')\n#7 /var/www/magento/src/vendor/magento/framework/Webapi/ServiceOutputProcessor.php(61): Magento\\Framework\\Webapi\\ServiceOutputProcessor->convertValue(Object(Magento\\SalesRule\\Model\\Data\\Rule), '\\\\Magento\\\\SalesR...')\n#8 /var/www/magento/src/vendor/magento/module-webapi/Controller/Rest/SynchronousRequestProcessor.php(99): Magento\\Framework\\Webapi\\ServiceOutputProcessor->process(Object(Magento\\SalesRule\\Model\\Data\\Rule), 'Magento\\\\SalesRu...', 'getById')\n#9 /var/www/magento/src/vendor/magento/module-webapi/Controller/Rest.php(188): Magento\\Webapi\\Controller\\Rest\\SynchronousRequestProcessor->process(Object(Magento\\Framework\\Webapi\\Rest\\Request\\Proxy))\n#10 /var/www/magento/src/vendor/magento/framework/Interception/Interceptor.php(58): Magento\\Webapi\\Controller\\Rest->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#11 /var/www/magento/src/vendor/magento/framework/Interception/Interceptor.php(138): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callParent('dispatch', Array)\n#12 /var/www/magento/src/vendor/magento/framework/Interception/Interceptor.php(153): Magento\\Webapi\\Controller\\Rest\\Interceptor->Magento\\Framework\\Interception\\{closure}(Object(Magento\\Framework\\App\\Request\\Http))\n#13 /var/www/magento/src/generated/code/Magento/Webapi/Controller/Rest/Interceptor.php(26): Magento\\Webapi\\Controller\\Rest\\Interceptor->___callPlugins('dispatch', Array, Array)\n#14 /var/www/magento/src/vendor/magento/framework/App/Http.php(135): Magento\\Webapi\\Controller\\Rest\\Interceptor->dispatch(Object(Magento\\Framework\\App\\Request\\Http))\n#15 /var/www/magento/src/generated/code/Magento/Framework/App/Http/Interceptor.php(24): Magento\\Framework\\App\\Http->launch()\n#16 /var/www/magento/src/vendor/magento/framework/App/Bootstrap.php(258): Magento\\Framework\\App\\Http\\Interceptor->launch()\n#17 /var/www/magento/src/index.php(39): Magento\\Framework\\App\\Bootstrap->run(Object(Magento\\Framework\\App\\Http\\Interceptor))\n#18 {main}"
}

Regression on issue #16

In #16, and associated PR #17, fixes were added to ensure that free gifts are not added to the cart during re-order.

This functionality is not working on Magento 2.4.4. I've not figured out quite when this broke, but I suspect the Magento core reorder code changed at some point.

Suggested solution
We have deployed the following code, which we suggest probably should be moved into this extension:

<type name="Magento\Quote\Model\Quote">
        <plugin name="gift_sales_rules_avoid_reorder_2" type="Vendor\SmileGiftSalesRule\Plugin\Quote\Model\Quote" />
</type>
namespace Vendor\SmileGiftSalesRule\Plugin\Quote\Model;

use Magento\Quote\Model\Quote as Subject;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\DataObject;
use Magento\Framework\App\RequestInterface;

class Quote
{
    public function __construct(
        protected RequestInterface $request
    ) {
    }

    /**
     * Avoid to add a gift product when adding an order item.
     * Avoids the re-ordering of gift-items.
     *
     * sales_order_reorder: Front-end re-orders
     * sales_order_create_reorder: Admin re-orders
     *
     * Smile used to handle this out the box in `magento2-module-gift-sales-rule/Plugin/Checkout/Model/Cart.php`,
     * but that logic doesn't work with the latest versions of Magento.
     * This code is based on that logic.
     *
     * @param Subject  $subject Subject
     * @param \Closure $proceed Parent method
     * @param ProductInterface $orderItem Order item
     * @param DataObject $request   Quantity flag
     *
     * @return Subject
     */
    public function aroundAddProduct(
        Subject $subject,
        \Closure $proceed,
        $orderItem,
        $request = null
    ) {
        if ((isset($request['gift_rule']) && $request['gift_rule']) &&
            (in_array($this->request->getFullActionName(), ['sales_order_reorder', 'sales_order_create_reorder'], true))
        ) {
            return null;
        }

        return $proceed($orderItem, $request);
    }
}

Gift product is not removed if condition changes

We have the following rule set up: If the quantity of certain products in cart is either 1,3,5,7, etc., one gift product is added to the cart. When I put 1 of these products in cart, I get one gift product.
However, when I put 2 products in cart, the first gift product is not removed, it is still in cart. Since the rule evaluates to false for 2 products, I would expect it to remove already added products.

It is also possible to remove the product from cart while keeping the gifted product.

Conditions of the rule not taken into account

I create a rule with following conditions :

image

I add to my cart a product which is NOT the "24-WG02".

The rule is displayed in my cart and I can choose gifts, but it should no be the case.

image

Button "Validate my gift(s)" should be always visible

Actually if there is a lot of potential gifts, I have to scroll to the bottom of the popin to see the button, which is a bit confusing.

The button should be outside of the "overflow:scroll" part (it's probably a bit complicated to do).

image

Unclear "limit of gift products" on frontend.

I create a rule with "Maximum number product offered" (missing translation here :) ) = 2.

On the cart page, I choose one gift, then another. They appear in my cart as attended.

If I select another gift, I got the message "You added gift product to your shopping cart." but the product is not added.

Maybe in this case we should have a message indicating clearly that maximum number of gifted products has been reached on the current cart.

Place order issue

Hello.
We faced loop issue, during place order , for which cart rule is applied.
During payment method save
vendor/magento/module-quote/Model/PaymentMethodManagement.php:52 is triggered CollectTotals process. And during this process triggered Observer vendor/smile/module-gift-sales-rule/Observer/SetNumberOfferedProduct.php ,in which quote is retrieved from session, and as it has TotalsCollected = false - process begin from scratch.
On the older version 1.1.0 - everything is OK.

Module version 1.1.1
Magento version Cloud 2.3.5 -p2

Best regards

Backend orders not working

Hello,
I can't make an order from Magento 2 backend when a free gift rule applies.
an error shows "requested qty is not available" although qty is available for all products including gift products.

Thank you

Conflict with claue theme

I'm using the Claue theme, and give me this error in the shopping cart:

configurable.js:49 Uncaught TypeError: Cannot read property 'bind' of undefined

This error means that configurable product options do not appear.

What can it be?

Seleção_107
Seleção_108
Seleção_109

Gifts "actions" conditions not persisted

On the BO, when I set a combination of conditions into the "Actions > Select free products" panel and I click "save", the conditions are not persisted when I reopen the rule.

I tested with "category", "attribute set", and "sku".

So it does also display every products of the catalog to be chosen as gifts on front (because no condition is evaluated).
Sélection_645

I use a Magento 2.3.0

Table smile_gift_salesrule is not generated, showing not exist.

D:\wamp64\www\magento\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:235, PDOException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.smile_gift_salesrule' doesn't exist at D:\wamp64\www\magento\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:228)"} []
[2019-08-20 12:03:22] main.CRITICAL: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.smile_gift_salesrule' doesn't exist, query was: SELECT t.* FROM smile_gift_salesrule AS t WHERE (rule_id = '15') {"exception":"[object] (Zend_Db_Statement_Exception(code: 42): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.smile_gift_salesrule' doesn't exist, query was: SELECT t.* FROM smile_gift_salesrule AS t WHERE (rule_id = '15') at D:\wamp64\www\magento\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:235, PDOException(code: 42S02): SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.smile_gift_salesrule' doesn't exist at D:\wamp64\www\magento\vendor\magento\zendframework1\library\Zend\Db\Statement\Pdo.php:228)"} []

Item free gift not load image in checkout

I created a promotion rule for the free gift to be inserted through a discount coupon.

If I insert the discount coupon in the cart it works normally.

However, if I add the discount coupon at checkout when the item is inserted, it has no image.

Could you help us to find the problem?

Here's a print illustrating it.
Captura_de_Tela_Area_de_Selecao_20220217114821

If I reload the page, the toast image works again, I think it must be a problem with the ajax request at checkout when it's a toast.

Cart Price Rule PHP exception

Prerequisites:

  • Magento 2.4.1 Commerce
  • application mode: production
  • php 7.4

Steps to reproduce:

  • go to Magento admin panel
  • navigate to Cart Price Rules
  • click 'Add New Rule'

Expected result:

  • user redirected to the 'New Cart Price Rule' page
  • user able to create a new rule

Actual result:

  • Magento 2.4.1 throws an exception
  • creating a new rule isn't possible

The Exception is being thrown when creating a new cart price rule. Basically, at that point, we have nothing in extension attributes of the Rule, meanwhile trying to access array offset on null. This leads to PHP notice and Magento exception.
1 exception(s): Exception #0 (Exception): Notice: Trying to access array offset on value of type null in /var/www/html/vendor/smile/module-gift-sales-rule/Plugin/Model/Rule/Metadata/ValueProviderPlugin.php on line 93

This #40 PR should solve the issue

Foreign key constraint fails when trying to save the new Cart Price Rule

Precondition:

  • Magento Commerce 2.4.2-p1 in Magento Cloud.
  • smile/module-gift-sales-rule, v1.1.8

Steps to reproduce:

Create a new Cart Price Rule.

Expected result:

The rule is successfully created.

Actual result:

Integrity constraint violation:
image

SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`dbname`.`smile_gift_salesrule`, CONSTRAINT `SMILE_GIFT_SALESRULE_RULE_ID_SALESRULE_RULE_ID` FOREIGN KEY (`rule_id`) REFERENCES `salesrule` (`rule_id`) ON DELETE CASCADE), query was: INSERT INTO `smile_gift_salesrule` (`rule_id`, `maximum_number_product`, `price_range`) VALUES (?, ?, ?)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.