Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Gadgetto last won the day on March 25

Gadgetto had the most liked content!

Community Reputation

369 Excellent

About Gadgetto

  • Rank
    Sr. Member
  • Birthday 10/05/1966

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
    Mattersburg / Austria

Recent Profile Visitors

979 profile views
  1. @Craig I submitted your report to GitHub issues in SnipCart repo: https://github.com/gadgetto/SnipWire/issues/3 You can follow the fix there!
  2. You are right @bernhard. And I didn't even know I could set selectors via array! I'm still scratching on the surface of ProcessWire... Code refactoring will be done when the module is in a stable state and I've implemented all necessary features.
  3. @bernhard, @dragan, Thanks a lot guys, I could fix it! It now runs bombproof - this is the final code: public function checkSKUUnique(HookEvent $event) { $snipwire = $this->wire('snipwire'); if (!$snipwire) return; $page = $event->arguments(0); if ($snipwire->isProductTemplate($page->template)) { $field = $page->getField('snipcart_item_id'); $sku = $page->snipcart_item_id; // SKU field value if (!$sku) return; // <- ###### only had to add this line if ($page->isChanged('snipcart_item_id')) { $exists = $this->wire('pages')->get("snipcart_item_id=$sku, id!=$page, status<" . Page::statusTrash); // <- ###### and change this line if ($exists->id) { // value is not unique! $error = $this->_('SKU must be unique'); $exception = sprintf( $this->_('SKU [%s] is already in use'), $sku ); $inputfield = $page->getInputfield($field); $inputfield->error($error); throw new WireException($exception); // Prevent saving of non-unique value! } } } }
  4. What I'm not sure about is: If I create a new page with the page editor, the creation process is split into 2 steps. In the first step you enter the title + name. Then you hit "Save". In the second step you can complete all other page fields and options. Are the other page fields (beside title and name) already available for API in first step? Probably not. So my test code from last post could work with "title" field but not with the other page fields?
  5. OK, here is the simplified code for testing in site/ready.php with "title" field used: // To test, add this to your sites/ready.php wire()->addHookAfter('Pages::added', 'presetTitleField', ['priority' => 99]); wire()->addHookAfter('Pages::saveReady', 'checkTitleUnique'); function presetTitleField(HookEvent $event) { $page = $event->arguments(0); $page->setAndSave('title', 'Test' . $page->id); } function checkTitleUnique(HookEvent $event) { $page = $event->arguments(0); $field = $page->getField('title'); $title = $page->title; if ($page->isChanged('title')) { $exists = wire('pages')->get("title=$title"); if ($exists->id) { // value is not unique! $error = __('Title must be unique'); $exception = sprintf( __('Title [%s] is already in use'), $title ); $inputfield = $page->getInputfield($field); $inputfield->error($error); throw new WireException($exception); // Prevent saving of non-unique value! } } } And thanks for the hint to extend the Page class with a new method!
  6. Thanks @bernhard, before I asked for help here, I searched for related information back and forth but couldn't find any relevant infos. The search results from your screenshot also didn't bring any light into this... 🙂
  7. This looks promising! Thank you. The problem is, I can't use this new class in my module as the PW version requirement is set to 3.0.148. I could borrow the code from this class and build my own method. This would require to rewrite a lot of code instead of getting the hooks working properly.
  8. Yes, I know this field type, but I don’t want to use third party modules in my module.
  9. Hi there, I'd like to prevent duplicate values in a specific page field (FieldtypeText) across all pages. The hook should also prevent saving of the page if a duplicate value is detected. Therefore I created two hook methods but I can't get it to work properly. Here are both hooks placed in init() method of an autoloader module: The first hook is to initially preset the field with the page id. The field value can be customized by the admin before saving. The second hook should check if the value is unique. If I create a new page and try to save, the WireException is already triggered in first step of page creation, where you enter the page title: SKU [] is already in use If I check the value of $sku (with Tracy) it's always empty! Any idea what could be wrong? EDIT: if I remove the second hook, the field value is correctly preset with the page id! $this->addHookAfter('Pages::added', $this, 'presetProductFields', ['priority' => 99]); $this->addHookAfter('Pages::saveReady', $this, 'checkSKUUnique', ['priority' => 101]); And this are the hook methods: public function presetProductFields(HookEvent $event) { $snipwire = $this->wire('snipwire'); if (!$snipwire) return; $page = $event->arguments(0); if ($snipwire->isProductTemplate($page->template)) { if ($page->hasfield('snipcart_item_id')) $page->setAndSave('snipcart_item_id', $page->id); } } /** * Check if the SKU value is unique across all product pages. * (Method triggered after Pages saveReady -> just before page is saved) * * @throws WireException * */ public function checkSKUUnique(HookEvent $event) { $snipwire = $this->wire('snipwire'); if (!$snipwire) return; $page = $event->arguments(0); if ($snipwire->isProductTemplate($page->template)) { $field = $page->getField('snipcart_item_id'); $sku = $page->snipcart_item_id; // SKU field value bd($sku); if ($page->isChanged('snipcart_item_id')) { $exists = $this->wire('pages')->get("snipcart_item_id=$sku"); if ($exists->id) { // value is not unique! $error = $this->_('SKU must be unique'); $exception = sprintf( $this->_('SKU [%s] is already in use'), $sku ); $inputfield = $page->getInputfield($field); $inputfield->error($error); throw new WireException($exception); // Prevent saving of non-unique value! } } } }
  10. Nova definitely supports language server protocol and comes with a bunch of predefined languages! The built in PHP extension is a bit rudimentary (like in VSCode) but there will be IntelliSense extensions available.
  11. Hey there, hope you are all well! I would like to introduce Nova from Panic.inc, a new IDE and code editor for web developers. The application is developed natively for macOS and is the successor of Coda 2 (if you know it). I'm sitting here in my home office (because of Corona) and yesterday I got the invitation for the beta. Now I have been testing Nova for about 1 day. The application is incredibly fast! I haven't used anything comparable so far (including VSCode). The user interface is very clean and skinnable. Here is a small excerpt of the already integrated features (which of course can be extended by plugins): - Project management - Integrated Remote Publishing - Integrated Git Handling (Push, Pull, Commit, etc...) - Integrated Code Completion (PHP, JavaScript, ...) - Full featured integrated remote file browser for all thinkable protocols - Integrated web preview - Integrated console (local and remote) - Tasks (this seems to be huge! I'm telling you more when I figured out what this can do) - etc... This will definitely be my IDE for the next years! Nova is currently in closed beta. No new tester are accepted. But should be in open beta in the next few weeks! Have a nice week and stay healthy! Greetings, Martin
  12. Hi @creativejay, do you still have this issue? If so, could you please file an issue in SnipWires GitHub repo and provide more information: https://github.com/gadgetto/SnipWire/issues I could not reproduce this problem but I think I have too little information.
  13. UPDATE 2020-03-21 SnipWire 0.8.5 (beta) released! This update improves SnipWires webhooks interface and provides some other fixes and additions: Catch module settings access for non super users Fixes [#2] Dashboard not accessible for non SuperUsers Added documentation (php comments) to Webhooks class and hookable event handler methods All Webhooks event handler methods now have a return value (Snipcart payload) Hookable event handler methods: All hookable event handler methods will return an array containing payload Snipcart sent to your endpoint. In addition the following class properties will be set: $this->payload (The payload Snipcart sent to your endpoint) $this->responseStatus (The response status your endpoint sent to Snipcart) $this->responseBody (The response body your endpoint sent to Snipcart) (Use the appropriate getter methods to receive these values!) How to use the hookable event handler methods (sample): $webhooks->addHookAfter('handleOrderCompleted', function($event) { $payload = $event->return'; //... your code here ... }); PLEASE NOTE: those hooks will currently only work when placed in init.php or init() or ready() module methods!
  14. Just placed the hook in init.php and now it all works! This is mysterious ...
  • Create New...