Drupal Commerce Order object extra data - entities

How might it be possible to get Commerce-Product-Display information in a Commerce-Order object?
The issue is I need to publish a Commerce-Product-Display node when a user has made a payment to publish the node. I am using Rules to detect the payment and attempt to publish the node.
My problem is, because the Completing the checkout process Rules event only has data for a Commerce-Order, and the Commerce-Order does not have information for the Product nor the Product display, I am unable to publish the node.

OK, so here's my new answer based on the new info you provided in your question
=================================
So this is probably a little more complicated than you expected, but not impossible! Two things are important:
the line-items that are attached to your order will contain your products and
you will need to use a rule component, in order to be able to have an additional 'condition-action' combo inside your rule action
Here is how to do it:
In your rule that is triggered upon 'Completing the checkout process', add a loop in your 'Actions' section. You should see 'Add loop' right next to 'Add action'. We'll use this loop to iterate through all the commerce-line-items in your order: that's where the products are hiding
When configuring the loop, tell it to iterate through 'commerce-order:commerce-line-items' and either rename, or remember what it's going to call each line item as it goes through it.
Now - as it's going through each of your order's line items, we'll want to call an entire new rule with its own set of 'condition' and 'action'. The condition we need is to check that the line item contains the product you expect, and the action can be whatever you want - publish a node based on a certain field or whatever. In my case, the action will just be sending an email to prove I found a product. When we need condition-action sets within a rule, we need to create a rule component!!
Go to /admin/config/workflow/rules/components to create a new rule component to run for each of the above items. Click the 'Add new component' link at the top of the page
Select 'Rule' from the drop-down options, since this will be a component that contains both a condition and an action
Name the rule, and in the 'Variables' section, we have to let it know we're going to pass it a parameter to work with. In our case, it will be the commerce line item that is currently being iterated through.
Add two conditions to your component (or whatever checks you think are necessary). I added 'Entity is of type' => Commerce Line item and 'Entity has field' => commerce_product. So this runs for all my products at the moment.
The condition I set on my component is to send an email, and I filled in the following for the body of the email: [line-item:commerce_product], and it prints out the product's name beautifully in the email each time I've tested checking out!
But first - how do I call this component for each of my line item types after I save it?? Read on:
After the component is saved, Add an action to your loop:
From now on, at the very bottom of your actions, you'll see a brand new 'Components' section, and in your case, you should only have one now. Select it to call it for each item:
Last step will be to fill in the parameter to pass to this component, which is obviously the list_item you're currently on, or whatever the computer name of the current item was if you changed it.
Save and test!
Whew! It's a little complicated, but I hope it puts you in the right direction!

The way rules work in Drupal is that not all fields are shown for your entity by default in the actions. What you need to do is prompt Rules to recognize your object as a certain type of node in order for the Rule to add all of its appropriate fields.
You can do this either by
using the 'Content is of type' under the Node section check (and select your Commerce Display node type or
directly using the 'Entity has field' check under the Entities section to check for a specific field you want to use.
Either of those should prompt Rules to recognize the type of entity you're working with and populate the Actions with the necessary fields.
Let us know if this works!

Related

JavaScript: how to trigger update form after setting input

I am writing a simple App Inventor program to populate a Covid-19 school health check page. I am stuck on selecting a school. Normally you type in a school name, the page finds string matches and you select from the list of string matched school. I am able to simply set the field manually but the rest of the form doesn't update. I know I must trigger an update but I cannot make head or tails of how this page works.
image of school selection
typing in part of school name
From the Chrome console I can do the following:
x = document.getElementsByClassName("k-textbox")
x[1].value = "Horace"
From the picture you can see the text was updated to "Horace" but the results have not updated. What should I do to force an update so the results list shows proper matches? Also, how do I query the matching results so I can confirm that my input was explicit enough to return a single match? FYI, this form entry page will be hidden to the user.
You can get the kendoDropDownList, call the read method from it's dataSource, and pass the locationName value of what you want. This won't set the text in the textbox, but it will filter your list down like you want.
To test, click on the input, open your console, and run the following:
$('#Location').data('kendoDropDownList').dataSource.read({ locationName: 'horace' })

How to save a record with validation rule in place

I currently have a validation rule that prevents user from making changes to a record when its status is completed. Users are only allowed to make changes if the status is either draft or registered.
AND(
TEXT(Current_Status__c) <> "Draft",
TEXT(Current_Status__c) <> "Registered"
)
There is a new requirement to allow user to update only a specific picklist value field even if the record status is completed. If i remove the validation rule, user will be able to change any fields on the page layout which won't work.
Object setting for the profile is read, create, edit. This object is a child object to Opportunity, OWD is controlled by parent.
Any recommendation on how to solve this issue ?
Thanks in advance.
We can rewrite your rule as ISPICKVAL(Current_Status__c, 'Completed') for example, looks bit cleaner. Your call though, you can keep as is.
So what you'd need is something like ISPICKVAL(Current_Status__c, 'Completed') && !ISCHANGED(Some_Picklist__c). It should let the edit through if you're modifying that picklist.
The problem is it won't check if that's the only change. Usercan cheat, modify 10 fields and they'll "piggyback" and save OK as long as one of them is that picklist.
It's pain to write validation like ISPICKVAL(Current_Status__c, 'Completed') && !ISCHANGED(Some_Picklist__c) && (ISCHANGED(Field1__c) || ISCHANGED(Field2__c) || ISCHANGED(Field3__c)). You'd have to add all editable fields to it, change it every time you make new one. And eventually you'll hit length limits.
I know 3 options for this if it's a concern for you:
Ask a developer to rewrite your logic to Apex trigger, it could then go dynamic through all fields (using "describe" calls to learn field names or stuff like getPopulatedFieldsAsMap.
Another trick is to allow editing completed records only through a quick action, not normal edit page. In that action you could set some hidden checkbox in the field prepopulating step and your validation would let the save through only if that checkbox is set. But then you need to deactivate it somehow anyway or the bypass will get permamently enabled.
If you don't have too many record types on the object a common trick is to change the record type on completion (workflow, process builder etc). And have another page layout with all fields locked down except that special picklist. It works good enough for UI changes but won't protect if you have code and integrations writing to the object too.

Peoplesoft Peoplecode events

i am new to Peoplesoft software and the PeopleCode programming. I have been doing alot of exercises with PeopleCode. I have a question whereby the record fields events such as FieldDefault and etc etc....
I have made an application whereby user can search and add new value. So in a case where I have Peoplecode in one of the event for example SaveEdit, when I click the save button in both cases of search data or adding new value tab, it points to the same PeopleCode.
Is there any method whereby the code will know when user are searching existing data or adding value or rows in PeopleSoft?
Wont it be conflicting for both cases to point to the same PeopleCode?
Another question:
Hi i have a question regarding the passing of variables between the FieldFormula event and SavePostChange.
I have some values being calculated in the FieldFormula and I want to access it in SavePostChange event as I want to prompt messagebox based on the value being calculated.
I have been using the Global variables to access the variables.
Is there any good way to pass the variables or access to the variables values?
In the case of search records, there are a couple of Search-specific events, SearchInit and SearchSave. SaveEdit is when the record is saving so it shouldn't have a conflict with Searchevents.
Additionally you can place code either in the Record PeopleCode (fires every time someone uses that Record in a Component) or in Component Record PeopleCode (just that component). Record PeopleCode fires first then Component Record PeopleCode. The Component PeopleCode also has additional events that the record level ones don't, like SavePreChange and SavePostChange. So once you get the hang who fires when you can get pretty granular control of the various events.
There is actually a pretty good summary in the PeopleBooks here.
Regarding your question of how to differentiate between adding a new value and working on existing one, I would suggest you to use %Mode variable in peoplecode.
When working on existing value %Mode takes the value as "U" ie Update Mode
If %Mode="U" then
/**YOUR CODE**/
End-if;
When working on New value %Mode takes the value as "A" ie Add Mode
If %Mode="A" then
/**YOUR CODE**/
End-if;

How to alert Magento Site Admin about abandoned cart?

How could we alert a magento site admin about each abandoned cart immediately after it is abandoned?
Is it a default feature in Magento EE?
No it is not a default feature in Magento EE.
You ask how a site admin could be alerted of an event that is somewhat of a grey area.
Assuming that an abandon cart is defined by the following criteria (which in fact is not the definition but may be applicable to you)
A registered user (ignore guest users for sake of sanity here) has products in cart.
This user does not complete the checkout and leaves the store-front
A period of time goes by (eg 1 day) with no adjustments on the cart items
Assuming this situation is your abandoned cart scenario i could suggest the following :
1.) I would use the Magento Quote Object (this is the object that is converted to an order after a successful checkout.)
looking at the quote object there already seems like there are enough fields to be able to monitor when the quote was created, when it was updated, when it was converted and whether it was converted or not. If the object does not contain the data fields you need there is no reason why you could not extend it. See a sample snapshot :
My (naive) suggestion would be to set up a scheduled job, to run at the same frequency at which you define your "abandoned cart" scenairio (or any frequency for that matter).
The job could do something like the following :
1.) Instantiate a collection of quotes.
2.) Filter out quote's that have been converted
3.) Filter out quote's that have been created recently (less than the critria above)
4.) Filter out quote's that have been modified within the same time-frame criteria
at this point you should have a list of all quote's that have been created, perhaps been updated but not converted for the last 24hours (depending on your criteria of course).
If you get to this point, well then the rest is straight forward.
Extract the information you need from the quotes (id's names, numbers, emails etc), compile your report and email to the administrator.
it the best idea i can think of for now! i have not done this in practice...
Ofcourse you can set-up funnels and goals with Google Analytic to give you extensive information on your customers, including abandoned carts, but that doesn't answer your question.

Convert Order into custom entity 'X'

Issue is :
I have one system Entity called 'Order' and another custom entity 'X'. I am looking for some kind of same functionality as available on Quote called 'Convert into Order'. I want the same functionality on Order form that there will be some button on it and when i click on it, it will create instance of entity 'X' and not only this, it will also transfer all the mapping attributes of Order and 'X', on the 'X' form.
Can any one share his experience or step to implement this?
Many thanks.
You would have to use JavaScript and call CRM web services on click of new button.
So you don't have to map your attributes of your entities in JavaScript, you could use InitializeFromRequest to achieve same result. I have used this way to programmatically qualify/disqualify leads and convert them to contact, account and opportunities.
There is a nice sample code for this on CodePlex:
http://www.codeproject.com/KB/cs/CRM_30___EntityMoniker.aspx
Please note, this code has a bug. Check Ronalds post for quick fix:
http://ronaldlemmen.blogspot.com/2008/09/convert-lead-to-contact-account-andor.html
Yuo could do this using an on demand triggered workflow. just create a workflow targting the order entity, have the first step create a new entity X by copying the valuses from the passed in order entity.
if you want the option to do this to show under the more actions menu instead of teh workflows one then you can edit the isv.config file.

Resources