Jump to content
Gadgetto

SnipWire - Snipcart integration for ProcessWire

Recommended Posts

UPDATE 2019-11-15

In the last 3 weeks I (nearly) finished the complete order handling for store merchants (ProcessWire backend). This includes the following features:

  • search for orders
  • filter orders
  • extensive overview of all order details
  • download of invoices
  • resend invoices to customers
  • refund amounts to customers

... all right from within your ProcessWire backend!

That doesn't sound like much, but it was a good piece of work. 🙂

Here is a short clip to demonstrate the new features:

order_handling.thumb.gif.4dc4ced581d0f2c409d62613bb8f3358.gif

  • Like 16
  • Thanks 1

Share this post


Link to post
Share on other sites

Hi @Gadgetto,

Thank you for this great module, currently I'am using it for a test-case.

When I updated with your recent version I get the following error when I want to navigate to the dashboard / products page:

Fatal error: Uncaught ProcessWire\PageFinderSyntaxException: Field does not exist: snipcart_item_id in /Users/macbookweb014/Documents/BB/localhost/wetthrasport/wire/core/PageFinder.php:1272 Stack trace: #0

Can you help me fixing it? Do I need to create a snipcart_item_id field?

Thanks in advance!

Kind regards, 
Peejay

 

Share this post


Link to post
Share on other sites
4 hours ago, Peejay said:

When I updated with your recent version I get the following error when I want to navigate to the dashboard / products page:

Fatal error: Uncaught ProcessWire\PageFinderSyntaxException: Field does not exist: snipcart_item_id in /Users/macbookweb014/Documents/BB/localhost/wetthrasport/wire/core/PageFinder.php:1272 Stack trace: #0

Can you help me fixing it? Do I need to create a snipcart_item_id field?

Hi @Peejay,

did you run the Additional stepsInstall Snipcart products package in SnipWire module settings?

This step installs product templates, files, fields and some demo pages required to build a Snipcart product catalogue. This additional step is needed to prevent unintended deletion of your Snipcart products catalogue when main module is uninstalled.

In the current alpha version this isn't yet checked by SnipWire.

If you did already run the additional step with an earlier SnipWire version there will be fields missing which were added in a later version. So you will need to re-run this step. The missing resources(fields, templates, pages, ...) will then be installed. Existing ones won't be touched!

To re-run this step, you will need to edit/remove a key in database directly:

DB table: "modules" -> find entry with class "SnipWire" -> edit the "data" field and remove the Json key: "product_package":true (be sure to leave a valid Json string - you will need to also remove the corresponding comma :

{"api_key":"YOUR_LIVE_API_KEY","api_key_test":"ODQzZTc1MjktZGQxNy00YmUzLWFkMWYtZDE3MDQ2YTk1ODNjNjM2ODE3NTg5NzUyNDQxOTc0","api_key_secret":"YOUR_LIVE_API_KEY_SECRET","api_key_secret_test":"","snipcart_environment":"0","single_page_shop":"","single_page_shop_page":1,"credit_cards":["visa","mastercard","amex"],"currencies":["eur","usd"],"show_cart_automatically":1,"shipping_same_as_billing":1,"show_continue_shopping":1,"split_firstname_and_lastname":1,"snipcart_debug":1,"snipcart_css_path":"https:\/\/cdn.snipcart.com\/themes\/2.0\/base\/snipcart.min.css","snipcart_css_integrity":"","snipcart_js_path":"https:\/\/cdn.snipcart.com\/scripts\/2.0\/snipcart.js","snipcart_js_integrity":"","include_jquery":"","jquery_js_path":"https:\/\/code.jquery.com\/jquery-3.3.1.min.js","jquery_js_integrity":"sha256-FgpCb\/KJQlLNfOu91ta32o\/NMZxltwRo8QtmkMRdAu8=","excluded_templates":["promailer-email","promailer-subscribe"],"cart_image_width":65,"cart_image_height":65,"cart_image_quality":70,"cart_image_hidpi":1,"cart_image_hidpiQuality":50,"cart_image_cropping":1,"data_item_name_field":"title","uninstall":"","submit_save_module":"Submit","taxes_included":1,"webhooks_endpoint":"\/webhooks\/snipcart","include_snipcart_css":1,"taxes":"[{\"name\":\"20% VAT\",\"numberForInvoice\":\"\",\"rate\":\"0.20\",\"appliesOnShipping\":[]},{\"name\":\"10% VAT\",\"numberForInvoice\":\"\",\"rate\":\"0.10\",\"appliesOnShipping\":[]},{\"name\":\"10% VAT (Shipping)\",\"numberForInvoice\":\"\",\"rate\":\"0.10\",\"appliesOnShipping\":[\"1\"]}]","snipwire_debug":1,"data_item_categories_field":"snipcart_item_categories","product_package":true}

After the key is removed, visit the SnipCart module settings again and re-run the product package installer!

In the release version of SnipCart, this will be handled automatically. On each update it will check if there are new fields or other resources to be installed.

Hope this helps!

p.s. You could also completely uninstall the SnipCart module and then reinstall - this should also activate the product package installer link!

-- Martin

  • Like 3

Share this post


Link to post
Share on other sites

@Peejay,

great!

what would be interesting for me is: do you think that the performance in SnipWire dashboard/backend is OK or do I need to find another way to fetch Snipcart data?

— Martin

Share this post


Link to post
Share on other sites

@Gadgetto,

For now the performance is OK! I'm still in testing mode. In two weeks I put the site live and when I have some orders I let you know how the performance is!

Pj

Share this post


Link to post
Share on other sites
21 minutes ago, Peejay said:

@Gadgetto,

For now the performance is OK! I'm still in testing mode. In two weeks I put the site live and when I have some orders I let you know how the performance is!

Pj

Thanks for reporting back!

I just published a new version on GitHub which has some great performance improvements and a lot of other new features!

The orders list is now loaded in 1 - 1.5 seconds (instead of 4 seconds).
The dashboard is also affected by these changes and should load much faster now!

  • Like 3

Share this post


Link to post
Share on other sites

Hi Martin,

that looks very promising! Unfortunately I can't get the module to work properly. I'm using the last dev version of processire. I get the following error when I try to install the sample products:
Raw data option with CURL not supported for GET 
In /wire/core/WireHttp.php line 642

Then I get when saving a product:
Snipcart product with SKU [1032] could not be fetched. [500 Internal Server Error: ]

I tried it in different environments, but in MAMP I also get these errors.

Share this post


Link to post
Share on other sites
6 hours ago, Noboru said:

Hi Martin,

that looks very promising! Unfortunately I can't get the module to work properly. I'm using the last dev version of processire. I get the following error when I try to install the sample products:
Raw data option with CURL not supported for GET 
In /wire/core/WireHttp.php line 642

Then I get when saving a product:
Snipcart product with SKU [1032] could not be fetched. [500 Internal Server Error: ]

I tried it in different environments, but in MAMP I also get these errors.

Hi @Noboru

I have a clue what's causing this problem. I need a little time. I'll contact you when I have fixed that.

In the meantime you could comment out the following lines in file SnipWire.module.php (should be line 96-98)

$this->addHookAfter('Pages::saved', $this, 'publishSnipcartProduct');
$this->addHookAfter('Pages::unpublished', $this, 'unpublishSnipcartProduct');
$this->addHookAfter('Pages::trashed', $this, 'unpublishSnipcartProduct');

-- Martin

  • Like 1

Share this post


Link to post
Share on other sites

@Noboru,

I just tried to reproduce the problem but couldn't. I installed ProcessWire 3.0.147 on a fresh MAMP host and installed SnipCart on the naked system. Also installed the additional resources package from within SnipWire settings - and it worked like expected.

Could you please provide more infos regarding your setup? PHP version, CURL version, additional installed modules, ...?

Share this post


Link to post
Share on other sites

I have a general question regarding required PW version for my upcoming SnipWire module:

SnipWire is a huge module which touches big parts of the PW core API. As a sample - only the WireHttp class had at least 10 fixes and improvements since v 3.0.123 which are mandatory for SnipWire to work properly.

I'm planning to release the module with a minimum requirement of PW version around 3.0.148  (which should represent the coming master version). Do you think this is a good idea or should I stay at - let's say 3.0.123 and struggle with many workarounds to stay downwards compatible?

Share this post


Link to post
Share on other sites

I would say that this answers your question 🙂

13 minutes ago, Gadgetto said:

SnipWire is a huge module which touches big parts of the PW core API. As a sample - only the WireHttp class had at least 10 fixes and improvements since v 3.0.123 which are mandatory for SnipWire to work properly.

Don't make more work for yourself, both in coding and in support.

 

  • Like 1

Share this post


Link to post
Share on other sites
12 minutes ago, rick said:

 

Don't make more work for yourself, both in coding and in support.

Completely agree. The module will only profit from you enjoying working on it, so go easy on yourself and make use of available core features where necessary. Besides, ProcessWire is ridiculously easy to keep updated, so I don't feel like you're leaving anybody behind.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, d'Hinnisdaël said:

Completely agree. The module will only profit from you enjoying working on it, so go easy on yourself and make use of available core features where necessary. Besides, ProcessWire is ridiculously easy to keep updated, so I don't feel like you're leaving anybody behind.

Exactly, I am always on the latest dev version whenever I need to work on a site as it is so easy to update, and it is always stable in my eyes.

Share this post


Link to post
Share on other sites
4 hours ago, Gadgetto said:

I'm planning to release the module with a minimum requirement of PW version around 3.0.148

+1 🙂

Share this post


Link to post
Share on other sites
5 hours ago, Gadgetto said:

my upcoming SnipWire module

BTW, when can we expect that to happen? Sounds like sooner than the end of December maybe? Is it going to be the first production ready version?

Thanks for sharing all your hard work, and do not forget to ship it with a "Donation button".

  • Like 3

Share this post


Link to post
Share on other sites
9 hours ago, Gadgetto said:

@Noboru,

I just tried to reproduce the problem but couldn't. I installed ProcessWire 3.0.147 on a fresh MAMP host and installed SnipCart on the naked system. Also installed the additional resources package from within SnipWire settings - and it worked like expected.

Could you please provide more infos regarding your setup? PHP version, CURL version, additional installed modules, ...?

Hi @Gadgetto,

I'm using MAMP Pro 5.5.1 with PHP 7.3.8 (tried it with 7.1.31 with the same result), 
 

/Applications/MAMP/Library/bin/curl --version
curl 7.65.1 (x86_64-apple-darwin13.4.0) libcurl/7.65.1 OpenSSL/1.0.2o zlib/1.2.8 nghttp2/1.29.0
Release-Date: 2019-06-05
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

It's also an naked PW 3.0.147 without any other modules.

Its the same result like on my webhost (curl 7.19.7 , PHP 7.3.12).

More testing on webserver (because webhooks and full configuration):
If I set the price to a value without a comma everything works as expected (SnipWire log: Fetched Snipcart product with SKU [1116] / ID [xxx-xxx-xxx-xxx]. 

But if the product price is for example 11.50, I get Snipcart product with SKU [1116] could not be fetched. [500 Internal Server Error: ]

I've tried different settings for decimal separator in app.snipcart.com Regional Settings.

The Markup for the Add-to-cart-Button looks like this:

 

<button class="snipcart-add-item" title="Add to cart" data-item-name="Axolotl Juicer" data-item-id="1116" data-item-price="11,5" data-item-url="https://roland.zumpixel.de/shop/axolotl-juicer/" data-item-description="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." data-item-image="https://xxx.xx.de/site/assets/files/1116/beer3.65x65-hidpi.jpg" data-item-metadata="{&quot;id&quot;:1116,&quot;created&quot;:1576098063,&quot;modified&quot;:1576185868,&quot;published&quot;:1576098063,&quot;created_users_id&quot;:41,&quot;modified_users_id&quot;:41}" data-item-quantity="1" data-item-quantity-step="1" data-item-stackable="true" data-item-taxable="true" data-item-taxes="20% VAT" data-item-has-taxes-included="true" data-item-shippable="true">Add to cart</button>

 

Armin

Edited by Noboru
more details

Share this post


Link to post
Share on other sites
1 hour ago, Noboru said:

Hi @Gadgetto,

I'm using MAMP Pro 5.5.1 with PHP 7.3.8 (tried it with 7.1.31 with the same result), 
 


/Applications/MAMP/Library/bin/curl --version
curl 7.65.1 (x86_64-apple-darwin13.4.0) libcurl/7.65.1 OpenSSL/1.0.2o zlib/1.2.8 nghttp2/1.29.0
Release-Date: 2019-06-05
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp 
Features: AsynchDNS HTTP2 HTTPS-proxy IPv6 Largefile libz NTLM NTLM_WB SSL TLS-SRP UnixSockets

It's also an naked PW 3.0.147 without any other modules.

Its the same result like on my webhost (curl 7.19.7 , PHP 7.3.12).

More testing on webserver (because webhooks and full configuration):
If I set the price to a value without a comma everything works as expected (SnipWire log: Fetched Snipcart product with SKU [1116] / ID [xxx-xxx-xxx-xxx]. 

But if the product price is for example 11.50, I get Snipcart product with SKU [1116] could not be fetched. [500 Internal Server Error: ]

I've tried different settings for decimal separator in app.snipcart.com Regional Settings.

The Markup for the Add-to-cart-Button looks like this:

 


<button class="snipcart-add-item" title="Add to cart" data-item-name="Axolotl Juicer" data-item-id="1116" data-item-price="11,5" data-item-url="https://roland.zumpixel.de/shop/axolotl-juicer/" data-item-description="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." data-item-image="https://xxx.xx.de/site/assets/files/1116/beer3.65x65-hidpi.jpg" data-item-metadata="{&quot;id&quot;:1116,&quot;created&quot;:1576098063,&quot;modified&quot;:1576185868,&quot;published&quot;:1576098063,&quot;created_users_id&quot;:41,&quot;modified_users_id&quot;:41}" data-item-quantity="1" data-item-quantity-step="1" data-item-stackable="true" data-item-taxable="true" data-item-taxes="20% VAT" data-item-has-taxes-included="true" data-item-shippable="true">Add to cart</button>

 

Armin

Regarding the CURL error in WireHttp - could you please provide the exact steps until the error occurres (starting from module installation?

The other problem: The data-item-price property is definitely wrong. It should be 11.5 not 11,5. I’ll need to check the float sanitizer. What is your locale setting?

BTW, Its really great to get SnipWire tested - this helps me a lot! Thanks @Noboru

Share this post


Link to post
Share on other sites
3 hours ago, szabesz said:

BTW, when can we expect that to happen? Sounds like sooner than the end of December maybe? Is it going to be the first production ready version?

Thanks for sharing all your hard work, and do not forget to ship it with a "Donation button".

It’s hard to tell when the first release version will be ready. I’m currently struggling with the custom taxes provider which will allow a very flexible VAT handling for all countries worldwide. I’m in contact with the Snipcart team, because I’m having problems with shipping taxes ...

When the taxes provider is finished, the biggest part is done and I should be able to release a first beta.

And thanks for the hint with the donation button! 👍

  • Like 3

Share this post


Link to post
Share on other sites
11 hours ago, Noboru said:

...
The Markup for the Add-to-cart-Button looks like this:


<button class="snipcart-add-item" title="Add to cart" data-item-name="Axolotl Juicer" data-item-id="1116" data-item-price="11,5" data-item-url="https://roland.zumpixel.de/shop/axolotl-juicer/" data-item-description="Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur." data-item-image="https://xxx.xx.de/site/assets/files/1116/beer3.65x65-hidpi.jpg" data-item-metadata="{&quot;id&quot;:1116,&quot;created&quot;:1576098063,&quot;modified&quot;:1576185868,&quot;published&quot;:1576098063,&quot;created_users_id&quot;:41,&quot;modified_users_id&quot;:41}" data-item-quantity="1" data-item-quantity-step="1" data-item-stackable="true" data-item-taxable="true" data-item-taxes="20% VAT" data-item-has-taxes-included="true" data-item-shippable="true">Add to cart</button>

 

FYI - @Noboru and I am just trying to solve the problem via PN chat (in German language). After I have fixed this, I'll post back the infos here!

  • Like 2

Share this post


Link to post
Share on other sites

With the help of @Noboru I could fix some bugs in the "Extended Resources" installer and with float values in prices. Some rare problems could be fixed and the installer is more stable now.

A big problem is the integrated taxes-provider regarding shipping-.taxes. I'm in contact with the Snipcart team to make this as flexible as possible. This isn't easy as we have very different taxes system around the countries of the world.

  • Like 4

Share this post


Link to post
Share on other sites

@Gadgetto this module looks fantastic! I'm looking at using SnipCart to create an ecommerce site because it seems very user friendly (important for when I pass this site off) and it has support for some of the features I need.

One of those features is subscriptions. Do you have advice for setting up monthly subscriptions vs one-time purchases? I'm new to both your module and SnipCart and I didn't see anything obvious after the initial install and a bit of poking about in the admin but I do see it in the Module's page under Setup and references to subscriptions in the module files.

Am I overlooking something, or do I just need to add custom fields to the snipcart-product template (and output them in the markup) to correspond to the button attributes listed in https://docs.snipcart.com/v3/setup/products ?

Thanks!

Share this post


Link to post
Share on other sites
20 hours ago, creativejay said:

@Gadgetto this module looks fantastic! I'm looking at using SnipCart to create an ecommerce site because it seems very user friendly (important for when I pass this site off) and it has support for some of the features I need.

One of those features is subscriptions. Do you have advice for setting up monthly subscriptions vs one-time purchases? I'm new to both your module and SnipCart and I didn't see anything obvious after the initial install and a bit of poking about in the admin but I do see it in the Module's page under Setup and references to subscriptions in the module files.

Am I overlooking something, or do I just need to add custom fields to the snipcart-product template (and output them in the markup) to correspond to the button attributes listed in https://docs.snipcart.com/v3/setup/products ?

I'm glad you like SnipWire! 🙂

Important: SnipWire is not yet ready for production environments!

Subscriptions are on my backlog and will be definitely in the first release!

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sten
      Hello
      Till now I hacked something with the twig template but it works no more with new PW versions so I look forward to create a module. I am working on a site in multiple languages : French, English, Italian, German, Spanish, Portuguese, Hebrew, Russian. The new posts are entered in any language with a field for language. Till now, I got twig files to get the translations with constants defined for each part of the pages.
      So I'd like to create a module to include theses files added according to the url /fr/en/...
      Have you some observations to do before I begin about the direction to take ?
      Thank you
    • By ukyo
      Mystique Module for ProcessWire CMS/CMF
      Github repo : https://github.com/trk/Mystique
      Mystique module allow you to create dynamic fields and store dynamic fields data on database by using a config file.
      Requirements
      ProcessWire 3.0 or newer PHP 7.0 or newer FieldtypeMystique InputfieldMystique Installation
      Install the module from the modules directory:
      Via Composer:
      composer require trk/mystique Via git clone:
      cd your-processwire-project-folder/ cd site/modules/ git clone https://github.com/trk/Mystique.git Module in live reaction with your Mystique config file
      This mean if you remove a field from your config file, field will be removed from edit screen. As you see on youtube video.
      Using Mystique with your module or use different configs path, autoload need to be true for modules
      Default configs path is site/templates/configs/, and your config file name need to start with Mystique. and need to end with .php extension.
      Adding custom path not supporting anymore !
      // Add your custom path inside your module class`init` function, didn't tested outside public function init() { $path = __DIR__ . DIRECTORY_SEPARATOR . 'configs' . DIRECTORY_SEPARATOR; Mystique::add($path); } Mystique module will search site/modules/**/configs/Mystique.*.php and site/templates/Mystique.*.php paths for Mystique config files.
      All config files need to return a PHP ARRAY like examples.
      Usage almost same with ProcessWire Inputfield Api, only difference is set and showIf usage like on example.
      <?php namespace ProcessWire; /** * Resource : testing-mystique */ return [ 'title' => __('Testing Mystique'), 'fields' => [ 'text_field' => [ 'label' => __('You can use short named types'), 'description' => __('In file showIf working like example'), 'notes' => __('Also you can use $input->set() method'), 'type' => 'text', 'showIf' => [ 'another_text' => "=''" ], 'set' => [ 'showCount' => InputfieldText::showCountChars, 'maxlength' => 255 ], 'attr' => [ 'attr-foo' => 'bar', 'attr-bar' => 'foo' ] ], 'another_text' => [ 'label' => __('Another text field (default type is text)') ] ] ]; Example:
      site/templates/configs/Mystique.seo-fields.php <?php namespace ProcessWire; /** * Resource : seo-fields */ return [ 'title' => __('Seo fields'), 'fields' => [ 'window_title' => [ 'label' => __('Window title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'attr' => [ 'placeholder' => __('Enter a window title') ] ], 'navigation_title' => [ 'label' => __('Navigation title'), 'type' => Mystique::TEXT, // or InputfieldText 'useLanguages' => true, 'showIf' => [ 'window_title' => "!=''" ], 'attr' => [ 'placeholder' => __('Enter a navigation title') ] ], 'description' => [ 'label' => __('Description for search engines'), 'type' => Mystique::TEXTAREA, 'useLanguages' => true ], 'page_tpye' => [ 'label' => __('Type'), 'type' => Mystique::SELECT, 'options' => [ 'basic' => __('Basic page'), 'gallery' => __('Gallery'), 'blog' => __('Blog') ] ], 'show_on_nav' => [ 'label' => __('Display this page on navigation'), 'type' => Mystique::CHECKBOX ] ] ]; Searching data on Mystique field is limited. Because, Mystique saving data to database in json format. When you make search for Mystique field, operator not important. Operator will be changed with %= operator.
      Search example
      $navigationPages = pages()->find('my_mystique_field.show_on_nav=1'); $navigationPages = pages()->find('my_mystique_field.page_tpye=gallery');
    • By Robin S
      This is a module I made as an experiment a while ago and never got around to releasing publicly. At the time it was prompted by discussions around using Repeater fields for "page builder" purposes, where the depth feature could possibly be used for elements that would be nested inside other elements. I thought it would be useful to enforce some depth rules and translate the depth data into a multi-dimensional array structure.
      I'm not using this module anywhere myself but maybe it's useful to somebody.
      Repeater Depth Helper
      This module does two things relating to Repeater fields that have the "Item depth" option enabled:
      It enforces some depth rules for Repeater fields on save. Those rules are:
      The first item must have a depth of zero. Each item depth must not be more than one greater than previous item depth. It provides a RepeaterPageArray::getDepthStructure helper method that returns a nested depth structure for a Repeater field value.
      Helper method
      The module adds a RepeaterPageArray::getDepthStructure method that returns a multi-dimensional array where the key is the page ID and the value is an array of nested "child" items, or null if there are no nested children.
      Example

      The module doesn't make any assumptions about how you might want to use the depth structure array, but here is a way you might use it to output a nested unordered list.
      // Output a nested unordered list from a depth structure array function outputNestedList($depth_structure, $repeater_items) { $out = "<ul>"; foreach($depth_structure as $page_id => $nested_children) { $out .= "<li>" . $repeater_items->get("id=$page_id")->title; // Go recursive if there are nested children if(is_array($nested_children)) $out .= outputNestedList($nested_children, $repeater_items); $out .= "</li>"; } $out .= "</ul>"; return $out; } $repeater_items = $page->my_repeater; $depth_structure = $repeater_items->getDepthStructure(); echo outputNestedList($depth_structure, $repeater_items);
       
      https://github.com/Toutouwai/RepeaterDepthHelper
      https://modules.processwire.com/modules/repeater-depth-helper/
    • By MoritzLost
      Cacheable Placeholders
      This module allows you to have pieces of dynamic content inside cached output. This aims to solve the common problem of having a mostly cacheable site, but with pieces of dynamic output here and there.  Consider this simple example, where you want to output a custom greeting to the current user:
      <h1>Good morning, <?= ucfirst($user->name) ?></h1> This snippet means you can't use the template cache (at least for logged-in users), because each user has a different name. Even if 99% of your output is static, you can only cache the pieces that you know won't include this personal greeting. A more common example would be CSRF tokens for HTML forms - those need to be unique by definition, so you can't cache the form wholesale.
      This module solves this problem by introducing cacheable placeholders - small placeholder tokens that get replaced during every request. The replacement is done inside a Page::render hook so it runs during every request, even if the response is served from the template cache. So you can use something like this:
      <h1>Good morning, {{{greeting}}}</h1> Replacement tokens are defined with a callback function that produces the appropriate output and added to the module through a simple hook:
      // site/ready.php wire()->addHookAfter('CachePlaceholders::getTokens', function (HookEvent $e) { $tokens = $e->return; $tokens['greeting'] = [ 'callback' => function (array $tokenData) { return ucfirst(wire('user')->name); } ]; $e->return = $tokens; }); Tokens can also include parameters that are parsed and passed to the callback function. There are more fully annotated examples and step-by-step instructions in the README on Github!
      Features
      A simple and fast token parser that calls the appropriate callback and runs automatically. Tokens may include multiple named or positional parameters, as well as multi-value parameters. A manual mode that allows you to replace tokens in custom pieces of cached content (useful if you're using the $cache API). Some built-in tokens for common use-cases: CSRF-Tokens, replacing values from superglobals and producing random hexadecimal strings. The token format is completely customizable, all delimiters can be changed to avoid collisions with existing tag parsers or template languages. Links
      Github Repository & documentation Module directory If you are interested in learning more, the README is very extensive, with more usage examples, code samples and usage instructions!
    • By MoritzLost
      This module allows you to integrate hCaptcha bot / spam protection into ProcessWire forms. hCaptcha is a great alternative to Google ReCaptcha, especially if you are in the EU and need to comply with privacy regulations.

      The development of this module is sponsored by schwarzdesign.
      The module is built as an Inputfield, allowing you to integrate it into any ProcessWire form you want. It's primarily intended for frontend forms and can be added to Form Builder forms for automatic spam protection. There's a step-by-step guide for adding the hCaptcha widget to Form Builder forms in the README, as well as instructions for API usage.
      Features
      Inputfield that displays an hCaptcha widget in ProcessWire forms. The inputfield verifies the hCaptcha response upon submission, and adds a field error if it is invalid. All hCaptcha configuration options for the widget (theme, display size etc) can be changed through the inputfield configuration, as well as programmatically. hCaptcha script options can be changed through a hook. Error messages can be translated through ProcessWire's site translations. hCaptcha secret keys and site-keys can be set for each individual inputfield or globally in your config.php. Error codes and failures are logged to help you find configuration errors. Please check the README for setup instructions.
      Links
      Github Repository and documentation InputfieldHCaptcha in the module directory (pending approval) Screenshots (configuration)

      Screenshots (hCaptcha widget)

       
       

       
×
×
  • Create New...