Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [plugin-development]

Questions having to do with constructing plugins.

1
vote
1answer
18 views

How can I load the templates from a module?

I'm creating a module that contains some predefined templates. How can I load them directly out of the vendor folder? I've tried doing Event::on(View::class, View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,...
1
vote
1answer
22 views

Ajax post request front-end csrf token

I'm trying to make a simple post request with ajax to a controller in plugin. The problem I'm having is that I always get a 400 Bad request because I don't send a valid CSRF Token. But I can't figure ...
1
vote
1answer
14 views

Open pop on click of custom action and get filled data

I created a new custom action. A new button is added in getAvailableActions(), now when i click on that button i want to open a pop up box ( i used Default pop up. Template File path : /craft/...
1
vote
1answer
23 views

What variables are available to redirectToPostedUrl?

Craft's Web Controller has a redirectToPostedUrl method. Copied here for the sake of discussion: public function redirectToPostedUrl($object = null, string $default = null): YiiResponse { $url = ...
1
vote
1answer
27 views

Craft 3: how to call methods in another plugin's service?

In Craft 2, we used to be able to do so by doing: craft()->plugin1->myMethod(); from Plugin 2's service for example. Now in Craft 3, I couldn't figure out a way to do it. Plugin1::$plugin-&...
1
vote
1answer
22 views

Custom plugin field in Table Columns?

I just created my first Craft 3 plugin. In the plugin I also have a custom (select)field. Everything is working as expected, which is great! But I can't for the life of me figure out, how to add this ...
1
vote
2answers
49 views

Craft 3: Cron job to run Controller actionIndex method of a Plugin

I have made a Craft 3 plugin that is manually used in the Craft Admin CP area; click a button and we sync products in Craft with a Shopify API. Now I am trying to automate the process. I would like ...
0
votes
0answers
21 views

Is it better to let Craft handle my API calls instead of recreating the same functions

First of all, I am just a student so please go easy on me. I am creating my first API for Craft cms and Commerce for an Android application. The steps I did was as follows: I created a plugin and ...
0
votes
0answers
12 views

Iterate through Super Table field in plugin

I have a Super Table field with two columns, one is a category field, the other an assets field (limit 1 on both). How can I iterate through it to get the category and asset selected for each row in ...
2
votes
1answer
23 views

Element API calling Module that integrates with third-party plugin

This is probably a bit niche but anyone especially au fait with the element api here? On project X I have a custom module within which I am referencing a service from another plugin (bolden/google-...
1
vote
0answers
13 views

How to modifyPaymentRequest() in Commerce 2?

Looks that I really used every functionality in my plugin that changed or has been removed in Commerce 2. :( I need to modify paypal transactionId and description what i did as follows in Commerce 1: ...
0
votes
0answers
7 views

No EVENT_DEFAULT_ORDER_STATUS in craft\commerce\services\LineItems?

The Commerce 2 docs shows LineItems::EVENT_DEFAULT_ORDER_STATUS as a parameter for the event beforeSaveLineItem and afterSaveLineItem, but craft\commerce\services\LineItems did not have a constant ...
1
vote
1answer
28 views

How to duplicate a matrix field programatically in Craft 3.1?

Is there a "Craft" way of handling this in 3.1? Solutions to this question on SE are based on older versions of Craft which no longer work. Custom fields can be duplicated by doing: $newEntry->...
2
votes
2answers
25 views

How do I prevent a controller from creating unwanted routes?

I have a custom module that is adding sections to the CP, like this: // Register CP routes Event::on( UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(craft\events\...
0
votes
0answers
16 views

Commerce 1 create a new order programmatically

How can this be done in PHP? I can't find anything in the docs.
1
vote
2answers
15 views

Commerce 1 get customer from user model

In PHP, is it possible to grab the customer model from a user model? EDIT: I just noticed that it is possible to attach a customer info field to the user. How do we achieve this?
1
vote
1answer
45 views

Charge Plugin - Stripe payments occasionally not being received in craft

I have some Charge payments on my website, and I have registered the onCharge event in my plugin, like so: public function init() { parent::init(); craft()->on('charge.onCharge', function(...
0
votes
1answer
31 views

How to reset a multi-value checkbox using EVENT_AFTER_SAVE_ELEMENT in Craft 3?

I'm porting the functionality of an existing plugin from another CMS into Craft 3 through a custom Craft module. The functionality is: When an option from a multi-value checkbox is checked on the "...
0
votes
0answers
21 views

Private Plugin Repository Using Satis

Has anyone been successful using Satis for composer repo(s) with Craft plugins? I have a repo set up with artifacts, that are posted as a public composer repo in the network. It finds the plugins and ...
1
vote
2answers
38 views

How can I save a tag value in an entry in Craft 3

I am working on a plugin and I have the following code private function _tagProducts(array $products, array $names) { foreach ($products as $productId) { $product = Craft::$app->...
1
vote
1answer
29 views

Multiple and or relatedTo in plugin element criteria

I am trying to return entries that relate to a series of categories. For example, I am trying to return clothing, in this example, I want to return all entries related to (flannel or denim) and (blue ...
1
vote
1answer
14 views

Craft 2 - Returning Value in Variable from Plugin to Template

I am working with a plugin and wish to return a value from it to the template that calls it. In my plugin, there is an XML feed call, and I would like to pass a value(variable) from the plugin to the ...
1
vote
1answer
23 views

Lowering memory usage on task batches

I build a plugin for Craft 2 which imports data from an excel file into craft commerce products. The problem is that it needs to import excels with like 10.0000 rows and 30 columns. I made a simple ...
1
vote
1answer
15 views

Getting orders by property in Commerce 2 from Plugin

In Commerce 1 i can select orders by a specific property as follows: $criteria = craft()->elements->getCriteria('Commerce_Order'); $criteria['orderStatusId'] = 1; return craft()->elements-&...
1
vote
1answer
20 views

Is it possible to create a new multisite site via a Craft Plugin/Module?

Does Craft provide a way to programmatically add a new multisite site through a plugin or module?
1
vote
1answer
16 views

Checking if user authored an entry in another channel while in loop, N+1 problem

I have 2 channels set up: Channel A and Channel B. I also have public registration so users can log in and fill out two forms (Form A and Form B), each form creating an entry in their respective ...
1
vote
1answer
16 views

Plugin not fully registered/enabled

I've created my first Craft3 plugin and installed it locally via a composer.json path. After doing the composer require, the plugin showed up as installed (with a green dot) under Admin->Settings->...
1
vote
2answers
48 views

DB Queries in Craft Commerce 2 with large data

Currently working on an e-commerce site, which currently has over 4000 products with a mass of variants (averaging 3 variants per product) - and hit a few hurdles on the way... At present, craft....
1
vote
1answer
20 views

How to set view path for rendering email templates?

Trying to send an email Craft::$app->setViewPath('/Users/stian/dev/site.com/templates/'); Craft::$app->mailer->compose('confirmation.twig', ['orderId' => $orderId, 'customerId' => $...
1
vote
1answer
18 views

How to get core shipping methods in Commerce 2? How to save an order?

Is there an equivalent function to commerce_shippingMethods->getAllCoreShippingMethods() in Commerce 2? I can only find Commerce::getInstance()->getShippingMethods()->getAllShippingMethods();...
1
vote
1answer
26 views

Is there an equivalent to IOHelper::ensureFolderExists in Craft 3?

Migrating Plugins to Craft 3 starts bugging me, seems that really everything changed. Is there an equivalent to IOHelper::ensureFolderExists in Craft 3?
1
vote
1answer
53 views

How do I create console commands for my module or plugin?

I would like to create a custom console command for my Craft 3 plugin. I've looked at the Yii docs and understand commands are defined using controllers extending \yii\console\Controller but cannot ...
1
vote
1answer
23 views

How to validate a form request

Is there anything with craft like Laravel's Form Requests? I am writing a plugin with a custom entry type. Right now, I am doing the store/edit pages and I do not want to reinvent the wheel ;) Is ...
1
vote
2answers
28 views

renderTemplate() renders the twig file without any CSS

I've set up the routing for a specific URL in my plugin to trigger the actionIndex controller method. I after logging a message to the Craft logs, I want to return the rendered twig file as the view, ...
2
votes
1answer
47 views

Can't get setFieldValue to work

I've got this // Creating users through frontend Event::on(Users::class, Users::EVENT_BEFORE_ACTIVATE_USER, function(UserEvent $event) { $userId = $event->user->id; // ...
1
vote
1answer
18 views

How to get instance of DiscountModel in Commerce 2?

In Commerce i got an instance of DiscountModel Class as follows: $discount = new Commerce_DiscountModel(); Is this the right way in Commerce 2? use craft\commerce\models\Discount as DiscountModel; ....
1
vote
1answer
11 views

What happened to commerce_discounts->saveDiscounts or How to relate vouchers to product types in Commerce 2?

We sell vouchers to our shop users. To prevent them for being used on vouchers themself, i could relate them to specific productTypes or even products in Commerce 1. craft()->commerce_discounts-&...
1
vote
1answer
25 views

Correct way to getOrderByNumber() from my Plugin in Commerce 2

I am migrating my plugin to Craft 3 / Commerce 2. What is the best way to call another plugins method like craft()->commerce_orders->getOrderByNumber($number) from my plugins service?
1
vote
1answer
53 views

How to modify and save a field in entry on EVENT_AFTER_SAVE in a plugin?

I'm trying to build my first little plugin. I'm stuck with a problem: I need to modify the value of the specific field reference, right after the saving of the entry because the new value is supposed ...
1
vote
1answer
18 views

Route directly to an S3-hosted asset?

I have a multi-site Craft install. I'd like to offer the ability for each site to upload an icon that will be used for favicons. I noticed a lot of 404s for both /favicon.ico and /apple-touch-icon....
1
vote
2answers
39 views

Plugin Error: “Unable to find component class”

I'm suddenly getting an error on my plugin fieldtype even though I didn't make any changes to it. On Craft's publish page where my field is supposed to be I get the error: Unable to find component ...
1
vote
0answers
20 views

Display Stripe card error in Craft 3 front-end entry form template

I have a custom plugin set up to speak to Stripe's API and process a card charge. The code triggers in a craft\elements\Entry::EVENT_AFTER_SAVE event because I want to pass along certain data about ...
1
vote
1answer
44 views

Adding entry type using setContentFromPost

I'm creating a new user using $user->setContentFromPost(). It all works fine except I can't attach an entry to an Entries field. $user = new UserModel(); $user->username = $email; $user-...
2
votes
1answer
24 views

Craft 3 Plugin not returning custom field value

I am trying to get the value of a custom field in entries, but I can't seem to get it to grab that value. I'm assuming I'm pulling it too early or too late, otherwise I have no idea. I can pull the ...
1
vote
2answers
71 views

Craft 3: Preventing Element from Saving in Plugin

I had a simple Password Confirmation validation function in Craft 2. In porting the function to Craft 3, I'm struggling to figure out how to handle the same thing. In Craft 2, all events were ...
1
vote
1answer
22 views

Setting plugin subnav to active

I have written a plugin that works fine, it has a subnav which i build like so: public function getCpNavItem() { $item = parent::getCpNavItem(); $item['subnav'] = [ 'moderateentries' =...
2
votes
2answers
93 views

How to render plugin templates in Craft CMS 3?

I cannot find a way to render templates from a plugin controller in Craft 3. I feel as though I've tried every variation advised online but for some reason this still isn't working. <?php ...
0
votes
1answer
27 views

Overwriting specific method in plugin

I want to expand functionality of perform plugin with generating pdf from message submission data and attaching it to email this plugin sends. I can't use events for this, because this plugin doesnt ...
1
vote
1answer
25 views

Connect to an external database from a Craft 2.x plugin

I recently saw a very helpful post about how to connect to an external database from a Craft plugin and I wanted to confirm I understood the implementation correctly. On this response the author ...
2
votes
1answer
106 views

Call function from plugin in template

In craft 2 I had a simple plugin that I used to run some php code. I could call the function like this. {{ craft.pluginname.functionname }} However I have been unable to do the same thing in craft 3....