I'm building in Ubercart the ability to sell membership subscriptions. So far, so good, but now I want to apply a discount of 33% to the price of a subs based on the country (from billing address) of the buyer.
In Drupal 7 this was done using Commerce with commerce_product_pricing, which allowed a Rule to apply a calculation (multiplication) to provide a percentage discount.
I've tried this using the Rules Action 'Calculate a value' which takes 'input value 1' (the price) and multiplies it by 'input value 2' (the discount = 0.333).
However, 'input value 2' can only be an integer. While writing this I realised I could instead divide by 3 to get the correct result (this worked, so I've left this detail here in case anyone else has this problem).
So all I need is to get Rules to identify the buyer's country from their billing address so I can block the purchase if their country is not in the list where the discount applies. However, if I add the Rule to trigger on checkout completion, and manage to obtain the billing address, I can't see how to stop the purchase from completing.
Currently trying to extract the Billing address country in Rules leads to this error:
Error: Call to undefined function entity_metadata_field_verbatim_get() in EntityStructureWrapper->getPropertyValue()
I'm clearly doing this wrong! Any suggestions gratefully received.
Comments
@nattywebdev, the "entity_metadata_field_verbatim_get" error is due to a bug in the module Addressfield. Can you please open an issue there? The fix is simple - change to "entity_plus_metadata_field_verbatim_get()" in line 1082 of addressfield.module
See if that change fixes your problem
Thanks @argiepiano. I made that change but now get a similar error:
Error: Call to undefined function entity_property_verbatim_get() in EntityStructureWrapper->getPropertyValue()
Am I chasing a related problem? Happy to log an issue once there's something clear to log!
You'll need to find all appearances of entity_property_verbatim_get and fix those too. That function doesn't exist in BAckdrop.
While you are there fix entity_property_verbatim_set to entity_plus_property_verbatim_set
AND make sure you enable Entity Plus
Thank you @argiepiano. In my project, entity_property_verbatim_set appears in:
so do I need to change all those too?
It also appears in:
and I assume that those should be left alone?
Sorry if this is obvious to you - it certainly is not obvious to me!
Hi @nattywebdev
Change it in all of these:
As for web/modules/entity_plus/entity_plus.api.php, files that end on api.php are never run (they are documentation files), so it doesn't matter, although I will make a note to change that in the module (I maintain Entity Plus).
As for these:
Those file belong to a module called Entity Metadata Wrapper, which should NOT be used, as it's deprecated and it duplicates functions from Entity Plus. Your site will crash if you enable both and you run any of those functions. It's probably disabled in your site. If it's not, you should disable it.
In any case, do not change those last 3 files, as those are needed as is by the old Entity Metadata Wrapper module (but I doubt it's currently enabled).
I have opened an issue in Entity Plus and Geofield. I closed the one I had opened in Addresfield, and opened a broader one that made it clear that Rules integration does not work with the current code. I'll provide PRs for both soon in case you want to use those, and test them, which would be really helpful as I don't currently use those fields with Rules.
Thank you - and of course yes, I will be glad to test.
Thanks. I provided a PR for addressfiled. It's linked here.
https://github.com/backdrop-contrib/addressfield/issues/32
Also clear the caches after fixing.