Coder Social home page Coder Social logo

torvista / zen_cart-back_in_stock_notifications Goto Github PK

View Code? Open in Web Editor NEW
0.0 3.0 1.0 1.1 MB

Customers can subscribe to a notification when a product in not in stock.

License: GNU General Public License v3.0

HTML 41.82% CSS 4.94% JavaScript 8.89% PHP 44.35%

zen_cart-back_in_stock_notifications's Introduction

Zen Cart - Back in Stock Notifications

If a product is out of stock, customers can subscribe/request to receive a notification when that product becomes available again.

This was based on the original CEON version, not the forked ajax version. Neither are supported anymore, but the functionality is well worthwhile, and I use it, so am encouraging use and development here despite it being the usual yelling into the void...

I've been modifying it for years, multi-language and attributes handling being the most significant omissions from the original code.

As a result, this code is hugely different from the plugin version, so always test on a development server: DO NOT drop it into your production server without testing first. It's compatible with the current Zen Cart 1.5.8 and php7.3+.

Note that the original documentation in the docs folder has NOT been updated, so the file list is out of date.

Installation/Upgrade

  1. On your development server, remove original BISN files.
  2. Copying all this fileset will not overwrite any other files: they are all new.
    But, regarding the template files, you will find bootstrap CLONE and responsive_classic CLONE folders containing modified template files (suffixed BISN php) for you to compare and merge into your own equivalents.

Go to the Admin Catalog->BISN Notifications Admin page to auto upgrade/install.

Use/How it Works

The use of the BISN service may be restricted to only logged-in users to prevent spam from the BISN form, or you can try the ReCaptcha plugin
https://github.com/torvista/Zen_Cart-Google_reCAPTCHA

The BISN observer determines if the product is out of stock and hence shows the BISN link and form.
The user fills in the form on the product info page or if logged-in, the data is filled automatically.
If the submitted form data has an error, the BISN subscribe page is shown, similar to Ask a Question. If the form data is valid, the BISN subscribe page is skipped, the subscripion is recorded and a success message is shown.

Languages

If you have a single language store, you should not see anything about languages.

For a multiple-language store, although real notification emails will be sent in the same language as that used by the customer for the subscription, it requires manual intervention.

This is done by selecting Option 4: this sends the emails in the language that matches the currently-selected admin-language. Then, changing the admin language will reload the Option 4 page and send the other emails that correspond to this other admin language etc.
Todo: make this automatic.

Testing

If you want to test the real sending of notifications repeatedly/not deleting the subscriptions:
in admin\back_in_stock_notifications.php
set this to false
$delete_customer_subscriptions = true;

The BISN configuration allows an alternative email destination for the test emails to prevent cluttering up the business email account while testing.

Optional copies of real Notification Subscription Emails are sent to what is defined in the BISN Admin (SEND_EXTRA_BACK_IN_STOCK_NOTIFICATION_SUBSCRIPTION_EMAILS_TO).

Ceon XHTML template

This plugin uses a unique (to CEON/Conor) method of building the forms and emails using templates and variable substitutions.
It's complicated to understand/modify, and something that needs replacing by ZC core methods... feel free to have a go and contribute that.

Problems/Ideas

Any problems or suggestions: open an issue in GitHub, not in the forum.

Changelog

16/08/2024: update and simplify template files

20/01/2023: added support for Google Recaptcha: https://github.com/torvista/Zen_Cart-Google_reCAPTCHA

18/11/2023 or thereabouts Add multi-language to email sending. A reply to the Admin copy of BISN subscription email now replies to customer Replace tabs with spaces with all files. Admin Option 1 list subscriptions by product Option 2 list all subscriptions Bugfix: handle fatal error for a missing/deleted product Added column sorts/set column sort links to table id anchor Hide model column if not used. Add Delete buttons for each product/subscription. Corrected paging display text. Added support for Google reCaptcha. And lots more fun for all the family.

11/11/2023: moved admin functions file so only loaded with BISN admin page Remove duplicated function zen_get_products_model from bis_functions.php Renamed BACK_IN_STOCK_NOTIFICATION_ENABLED to BACK_IN_STOCK_NOTIFICATIONS_ENABLED Minor changes to installer messages and processing. Add delete of single subscriptions of a product

06/11/2023: relocated required/optional template files to main file structure. Updated template files based on ZC158 responsive_classic.

23/07/23: Use ZC158 admin header, move css to separate file.

16/02/22: Bugfix for duplicated subscription links when no login required.

Removed: /modules/ceon_form_bis as functionality duplicated in observer class

Removed: unnecessary observer auto loaders/observers made auto-loading

Bugfix for missing product_model in account BISN listing

Bugfix for missing image in account BISN listing, Update button

Modified: language defines

Removed: modified core file functions_general

Removed: empty language folders

Fixes for warnings in strict mode/php8 compatibility

Miscellaneous IDE recommendations, strict comparisons, short-array syntax

zen_cart-back_in_stock_notifications's People

Contributors

torvista avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

billj9000

zen_cart-back_in_stock_notifications's Issues

Spammers sending malicious links in NAME field

It seems that spammers are using the module to send SPAM LINKS which contain malicious links in the NAME field.

The module only asks for three fields: Name, Email Address, and Confirm Email Address. What is happening is that they put a legitimate email address in the two fields (the person they want to spam), but they put their malicious link in the NAME field. Since the form is submitted and authenticated by our own SMTP domain, it isn't seen as SPAM (since our domain is originating the email) and it gets sent to the customer.

Here is a screenshot of what the SPAM looks like: https://i.postimg.cc/c15tMdZj/screenshot-132.png

Notice that in this example, the NAME FIELD that the spammer used was: "๐Ÿ’ Amber want to play with you! Start Game: https://letsg0dancing.page.link/go?exx ๐Ÿ’"

So when the recipient (whose address is entered in the email field) opens the Back In Stock email, the very first line (which is the NAME field) contains the malicious link.

SOME THOUGHTS ON ADDRESSING THE ISSUE:

  1. Some sort of CAPTCHA might be applied to help reduce automated spammers from abusing the form. However, this won't stop spammers from manually entering in the information.

  2. At the very least, perhaps run a string-check on the NAME and reject anything that is 1) over a certain amount of characters, and 2) reject anything that has an "HTTP" or ".com" in it, and 3) reject any name with "more than two blank spaces" in it.

That alone should weed out most fake names, since most names won't be over about 10 characters, and most won't have a www/http string, and most won't have more than two blank spaces (John Smith Jr, etc).

  1. As a complete fail-safe, perhaps having an option to DISABLE the NAME field would work. In other words, only allow an email address to be entered. This would still "spam" though, but it won't contain any malicious links because there would be no name field.

PHP Fatal error: 1055:'DBNAME.pd.products_name' isn't in GROUP BY :

php 8.1.9
When entering admin BISN page.

--> PHP Fatal error: 1055:'DBNAME.pd.products_name' isn't in GROUP BY ::
SELECT bisns.product_id, pd.products_name, p.products_model, COUNT(*) AS num_subscribers, p.products_type, p.products_quantity AS current_stock, cd.categories_name, cd.categories_id , bisns.product_name_extra FROM back_in_stock_notification_subscriptions bisns LEFT JOIN products_description pd ON (pd.products_id = bisns.product_id AND pd.language_id = '1') LEFT JOIN products p ON p.products_id = pd.products_id LEFT JOIN categories_description cd ON (p.master_categories_id = cd.categories_id AND cd.language_id = '1') WHERE 1 = 1 GROUP BY bisns.product_id ORDER BY p.products_model
==> ADMIN\back_in_stock_notifications.php on line 165.

PHP Fatal error: Uncaught Error: Undefined constant "BACK_IN_STOCK_REQUIRES_LOGIN"

[15-Feb-2022 20:23:03 America/Vancouver] PHP Fatal error: Uncaught Error: Undefined constant "BACK_IN_STOCK_REQUIRES_LOGIN" in /usr/home/sites/zen15/www/includes/languages/english/extra_definitions/back_in_stock_notifications.php:23
Stack trace:
#0 /usr/home/sites/zen15/www/includes/modules/extra_definitions.php(45): include()
#1 /usr/home/sites/zen15/www/includes/init_includes/init_templates.php(85): include('/usr/home/sites...')
#2 /usr/home/sites/zen15/www/includes/autoload_func.php(37): require_once('/usr/home/sites...')
#3 /usr/home/sites/zen15/www/includes/application_top.php(222): require('/usr/home/sites...')
#4 /usr/home/sites/zen15/www/index.php(25): require('/usr/home/sites...')
#5 {main}
thrown in /usr/home/sites/zen15/www/includes/languages/english/extra_definitions/back_in_stock_notifications.php on

--- /usr/home/sites/zen15/www/includes/languages/english/extra_definitions/back_in_stock_notifications.php.old  2022-02-15 20:27:17.771032000 -0800
+++ /usr/home/sites/zen15/www/includes/languages/english/extra_definitions/back_in_stock_notifications.php      2022-02-15 20:30:26.138009000 -0800
@@ -20,7 +20,7 @@
  * Note that the link is added in place of %s, %s must be present for the link to work!
  */
 define('BACK_IN_STOCK_NOTIFICATION_TEXT_PRODUCT_LISTING_ALREADY_SUBSCRIBED', '<br />You have requested to be notified when this product is back in stock.');
-if (BACK_IN_STOCK_REQUIRES_LOGIN == '1') {
+if (defined('BACK_IN_STOCK_REQUIRES_LOGIN') && BACK_IN_STOCK_REQUIRES_LOGIN == '1') {
   define('BACK_IN_STOCK_NOTIFICATION_TEXT_PRODUCT_LISTING_FORM_LINK', '<br />To be notified when this product is back in stock please <a href="%s">click here</a>. (Requires account)');
 } else {
   define('BACK_IN_STOCK_NOTIFICATION_TEXT_PRODUCT_LISTING_FORM_LINK', '<br />To be notified when this product is back in stock please <a href="%s">click here</a>.');
@@ -30,7 +30,7 @@
  * Text/HTML for other pages.
  */
 define('BACK_IN_STOCK_NOTIFICATION_TEXT_ALREADY_SUBSCRIBED', 'You have requested to be notified when this product is back in stock.');
-if (BACK_IN_STOCK_REQUIRES_LOGIN == '1') {
+if (defined('BACK_IN_STOCK_REQUIRES_LOGIN') && BACK_IN_STOCK_REQUIRES_LOGIN == '1') {
   define('BACK_IN_STOCK_NOTIFICATION_TEXT_FORM_LINK', 'To be notified when this product is back in stock please <a href="%s">click here</a>. (Requires account)');
 } else {
   define('BACK_IN_STOCK_NOTIFICATION_TEXT_FORM_LINK', 'To be notified when this product is back in stock please <a href="%s">click here</a>.');

PHP Fatal error: bisns.name' isn't in GROUP BY: Admin, Preview Emails

PHP Fatal error: 1055:'DBNAME.bisns.name' isn't in GROUP BY ::
SELECT
bisns.email_address, bisns.name, bisns.languages_id, c.customers_email_address, c.customers_firstname,
c.customers_lastname
FROM
back_in_stock_notification_subscriptions bisns
LEFT JOIN
products p
ON
p.products_id = bisns.product_id
LEFT JOIN
customers c
ON
c.customers_id = bisns.customer_id
WHERE
p.products_quantity > 0
AND
bisns.languages_id = 1
GROUP BY
email_address, customers_email_address
ORDER BY
email_address, customers_email_address ==> (as called by) ADMIN\includes\functions\back_in_stock_notifications_functions.php on line 82 <== in includes/classes/db/mysql/query_factory.php on line 665.

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.