-
Posts
63 -
Joined
-
Last visited
Spinbox's Achievements
![Rank: Full Member (4/6) Full Member](http://processwire-forums.s3.us-west-2.amazonaws.com/set_resources_6/84c1e40ea0e759e3f1505eb1788ddf3c_default_rank.png)
Full Member (4/6)
38
Reputation
-
Thank you for your reply. First of all, I'm more of a frontender, which could lead to not providing all the things you would like too. Sorry if this leads to unclear questions. Learning each day though. I'm happy to provide a PR but the problem is I'm not sure if I'm right or what I'm doing is the right 'way', or let's say I'm not that confident. What I want to achieve This is what I'm trying to achieve, by adding functions/extensions/filters to twig. <h2>{{translate('Articles','General')}}</h2> <p>{{page.article_date|format_datetime(pattern="d MMMM yyyy")}}</p> Suggestion My suggestion is to have a separate function to load twig (just like Latte is loaded right now), like mentioned in my previous post. This hook would then be able to add these extensions etc. $this->wire()->addHookAfter('RockFrontend::loadTwig', function (HookEvent $event) { /** @var \Twig_Environment $twig */ $twig = $event->return; // Adding custom Twig extensions, functions, and filters $twig->addExtension(new IntlExtension()); $twig->addFunction(new \Twig\TwigFunction('translate', function ($text, $context = "General") { return _x($text, $context, config()->urls->templates . 'language/translations.php'); })); $twig->addFilter(new \Twig\TwigFilter('html_entity_decode', 'html_entity_decode')); $twig->addFilter(new \Twig\TwigFilter('base64_encode', 'base64_encode')); $twig->addFilter(new \Twig\TwigFilter('base64_decode', 'base64_decode')); $twig->addFunction(new \Twig\TwigFunction('bd', function ($dump) { bd($dump); })); // Return the modified Twig environment $event->return = $twig; }); I'm not sure how this would work. My first thought are that I have to copy the contents of this function into a hook and then change the part where it was going to call the renderFileTwig(). That seems like it's prone to errors if the module gets updates but I could be wrong. Any pointers in how to approach this would be welcome.
-
I used to use TemplateEngine with Twig, where I could hook into twig to add extensions and functions. Is it possible to make it hookable? Right now we can use Twig, but very limited, or am I wrong? Perhaps changing to current function /** * Twig renderer */ protected function renderFileTwig($file, $vars) { try { require_once $this->wire->config->paths->root . 'vendor/autoload.php'; $loader = new \Twig\Loader\FilesystemLoader($this->wire->config->paths->root); $twig = new \Twig\Environment($loader, [ 'debug' => true, ]); $twig->addExtension(new \Twig\Extension\DebugExtension()); $relativePath = str_replace( $this->wire->config->paths->root, $this->wire->config->urls->root, $file ); $vars = array_merge((array)$this->wire('all'), $vars); return $twig->render($relativePath, $vars); } catch (\Throwable $th) { return $th->getMessage() . '<br><br>Use composer require "twig/twig:^3.0" in PW root'; } } to something similar like the Latte renderer /** * Twig renderer */ protected function renderFileTwig($file, $vars) { $twig = $this->loadTwig(); if (!$twig) throw new WireException("Unable to load Twig"); $vars = array_merge((array)$this->wire('all'), $vars); $relativePath = str_replace( $this->wire->config->paths->root, $this->wire->config->urls->root, $file ); return $twig->render($relativePath, $vars); } public function ___loadTwig() { if ($twig instanceof \Twig\Environment) return $this->twig; try { require_once $this->wire->config->paths->root . 'vendor/autoload.php'; $loader = new \Twig\Loader\FilesystemLoader($this->wire->config->paths->root); $twig = new \Twig\Environment($loader, [ 'debug' => true, ]); $twig->addExtension(new \Twig\Extension\DebugExtension()); return $this->twig = $twig; } catch (\Throwable $th) { $this->log($th->getMessage()); return false; } }
-
Hi @kongondo, you have any updates on the fix?
-
I'm having an issue where the total price with tax differs from the unit price with tax for a product. The store also has 'All taxes are included in stated prices' checked under tax settings and tax is set at 21%. Is there a fix planned for this or can I hotfix this for now?
-
Not able to retrieve/generate product variant attributes
Spinbox replied to Spinbox's topic in Padloper Support
Thank you @kongondo, You got me on the right path and I have found the issue. My homepage template has url segments enabled. Once I disable this, the url works. Not sure if this contributes to the problem but I use TemplateEngineFactory. To keep url segments I used a regex to allow anything but paths that start with find-padloper in the template settings. regex:^(?!find-padloper).*$ -
Not able to retrieve/generate product variant attributes
Spinbox replied to Spinbox's topic in Padloper Support
Thanks for looking into it, I'm going to check what could be the problem.. -
Not able to retrieve/generate product variant attributes
Spinbox replied to Spinbox's topic in Padloper Support
Hi @kongondo, no I am not running of a sub-directory. I haven't changed anything, so I assume it uses the default language (in my case Dutch). I'm not sure it has anything to do with language. Isn't it just looking for the default language values? -
I'm having problems with retrieving attributes for Variants. This hook seems to not triggering for me: $this->addHook("/find-padloper_product_attributes/", $this, 'hookFindPadloperProductAttributesOptions'); When trying to find attributes it returns a 404. I'm using multilingual fields.
-
Works for me!
-
I phrased it wrong. I can save it, but I'd rather not have my client confused π thanks!
-
After updating I can't simply save an existing product. Is it possible to keep the compare price empty? Looks like it's not possible and it resets to 0. Probably because of the database type.
-
Great stuff π Can't wait to use it!
-
Limit the amount of products a user can purchase
Spinbox replied to Spinbox's topic in Padloper Support
Great stuff! Cheers π -
I have managed to save the charge id to the order. For this to work I needed to make captureOrder hookable. This is probably not the right way tough.. $wire->addHookAfter('PadloperProcessOrder::captureOrder', function(HookEvent $event) { $paymentIntent = $event->return; $orderId = $paymentIntent->metadata->reference_id; if ($paymentIntent && $paymentIntent->status === 'succeeded') { $chargeId = $paymentIntent->latest_charge; // Load the order page using the order ID and save the charge ID $orderPage = wire()->pages->get("template=padloper-order, id={$orderId}"); if ($orderPage->id) { $orderPage->of(false); $orderPage->set('stripe_charge_id', $chargeId); $orderPage->save(); } } });