Closed (fixed)
Project:
Ubercart Addresses
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
27 Jan 2013 at 22:58 UTC
Updated:
14 Mar 2013 at 08:40 UTC
Jump to comment: Most recent file
Comments
Comment #1
megachrizSo your use case is to check if the customer has any address in his/her address book that has the "sibling" box checked? I'm afraid that isn't possible to do in Rules at the moment without custom code. I assume your were trying to access the addresses via the user object and the default addresses are there, because they are exposed as tokens.
If, on the other hand, you were trying to check if the customer has checked that box on the checkout page for either the delivery or billing address, then you should access the custom field via the order object instead.
For understanding your use case better, it may help to post an export of the Rule you are trying to create.
Comment #2
lhubbert commentedHi Mega - the second is what I'm trying to do. I only want to check the billing address of the current order, which has a custom checkbox for Sibling. I believe I should do a Data Comparison, with the Data Selector "current-order:billing-address:" but there are no custom options available for the custom field (see attached). Thanks if you can help - this is the last thing I need to get in place to be ready to launch.
Lisa
Comment #3
megachrizI have taken a look in Rules and I guess I was wrong about that tokens would be exposed in Rules in data selectors. With me, custom extra address fields didn't show up either. I have an idea about how I could expose the extra fields for the data selector, but that might quite take some time to implement if I would take it carefully (thus to be sure without breaking any other functionality). Anyway, I already found out that it would be a lot easier to do if addresses (from Ubercart Addresses) were entities. I already started to work on that, see #1831424: Turn Ubercart Addresses address into an entity and it's near finished. But it still could mean it could take a few weeks before I can came up with a decent solution for this issue (one that is tested very well).
"Execute custom PHP code"
As a workaround, you could use PHP in Rules to check if the checkbox is checked. There are two address objects attached to the order (instances of UcAddressesAddress). These can be accessed like this:
On the address object you can call the method
getField()to get the value of your custom field. See also the documentation about this.I assume you created the extra field with the Extra Fields Pane module. In that case, your PHP rule would look something like this:
If your field was created in an other way, you would still access the field the same way, but your field's name would probably not have the 'ucxf_' prefix.
So, to sum things up:
If you would like to help with coding and testing to get the extra address fields as selectable data in Rules, let me know and then I will explain my ideas about it in more detail.
Comment #4
lhubbert commentedHi Mega,
I know I had looked at #1831424: Turn Ubercart Addresses address into an entity while I was trying to solve the problem. Glad I was on the right path with that. I definitely am using the Extra Fields module (and my field is 'ucxf_sibling' as you note).
I toyed with the PHP above but honestly that's out of my skillset to figure out. We go live in two weeks or so, I'll keep an eye on your entity project. If I have to I can use a "SIBLING" discount code, just so much less elegant than an automatic discount based on a checkbox.
Thanks for detailing the issues so clearly. I'd love to get this working but don't want to take your time to solve it.
Lisa
Comment #5
megachrizHm, well then it's likely you have to go for the less elegant way for now. I'd like to solve this issue anyway, as having extra address fields as selectable data in Rules could be useful for other use cases also. As I look how far I am with the entities thing, it might be possible to implement a solution for this issue within two weeks, but I can't make any promises.
I will not pick this issue up until I'm sure #1831424: Turn Ubercart Addresses address into an entity is fixed, thus until then this issue is postponed.
Comment #6
lhubbert commentedHey Mega, I saw you committed #1831424. I updated to dev, but didn't see any change. Is there a specific thing I should be doing to see custom fields available to Rules? I'd love to make my discounts work this way and have a few more days to tweak before we go live.
Thanks,
Lisa
Comment #7
megachrizI still have to make a fix for this issue. I have an experimental fix for this locally, maybe I can post that later today here as a patch.
Be careful with the dev, though. Since the entity integration is pretty new, it could have issues in combination with other modules that act upon entities, though I did test the implementation with Views, Panels, partly with Rules and with most common Entity API functions.
Comment #8
megachrizThis patch tells Entity API about the address objects that are attached to the order. After applying the patch and clearing the caches, you should be able to access extra fields via
order:uc-addresses-billing-addressfor the billing address andorder:uc-addresses-delivery-addressfor the delivery address.Note that the properties
order:billing-addressandorder:delivery-addressare also available, but you won't find the extra fields there. I chose to declare two new properties instead of overwriting the two existing ones to avoid possible conflicts.Let me know if this works for you. :)
Comment #9
megachrizIn addition of the patch in #8, this patch also exposes the default addresses of the user object to Rules. I've done a few testing with this and I think this code is enough to get access to (custom) address fields in Rules (in user context and Ubercart order context).
Let me know if something still misses! Else, I assume this patch is complete.
Comment #10
megachrizI think the patch exposes the custom address fields in Rules correctly for the order object and for the user object. Committed #9.