When adding custom php code for a conditional action, drupal/ubercart provides two php variables ($order and $account) that hold information about the order and account for the checkout that was just completed.
I can't find anywhere on the internet documentation about how these objects are structured...anyone know where this documentation is or how these objects are setup???
thanks
Here's what the $order object looks like on a fairly standard install (might be a bit different depending on your installation. Of course the products in the order dictate what the items section looks like:
stdClass Object
(
[order_id] => 123
[uid] => 456
[order_status] => payment_received
[order_total] => 100
[product_count] => 1
[primary_email] => test#example.com
[delivery_first_name] => Test
[delivery_last_name] => Customer
[delivery_phone] => 123-123-1234
[delivery_company] => ABC Company, Inc.
[delivery_street1] => 123 Easy St.
[delivery_street2] =>
[delivery_city] => Anytown
[delivery_zone] => 39
[delivery_postal_code] => 12345
[delivery_country] => 840
[billing_first_name] => Test
[billing_last_name] => Customer
[billing_phone] => 123-123-1234
[billing_company] => ABC Company, Inc.
[billing_street1] => 123 Easy St.
[billing_street2] =>
[billing_city] => Anytown
[billing_zone] => 39
[billing_postal_code] => 12345
[billing_country] => 840
[payment_method] => credit
[data] => Array
(
[cc_data] => ***encrypted credit card data***
)
[created] => 1295455508
[modified] => 1295457962
[host] => 127.0.0.1
[products] => Array
(
[0] => stdClass Object
(
[order_product_id] => 245
[order_id] => 123
[nid] => 5
[title] => Test Product
[manufacturer] =>
[model] => TEST-PRODUCT-SKU
[qty] => 1
[cost] => 100.00000
[price] => 100.00000
[weight] => 0
[data] => Array
(
[attributes] => Array
(
)
[shippable] => 1
[module] => uc_product
)
[order_uid] => 456
)
)
[payment_details] =>
[quote] => Array
(
[method] => flatrate_1
[accessorials] => 0
[rate] => 7.00000
[quote_form] =>
)
[line_items] => Array
(
[0] => Array
(
[line_item_id] => subtotal
[type] => subtotal
[title] => Subtotal
[amount] => 100
[weight] => 0
[data] =>
)
[1] => Array
(
[line_item_id] => 194
[type] => shipping
[title] => Flat Rate Shipping
[amount] => 7.00000
[weight] => 1
[data] =>
)
)
)
$account is the user object.
$order is the ubercart order object.
There are some minimum defined values for both of these objects, but they can contain anything really. The reason is, that Drupal will allow modules to expand the user object, while ubercart will allow modules to expand the order object.
The best thing to do in such situations is to inspect the objects to figure out how to get to what you need.
The devel module will allow you to pretty print variables using dsm() or dump the variable t a log file using dd(). Those are two ways to get to the variable info.
Related
I use the following function call to get a product variations,
$available_variations = $product->get_available_variations();
And in the returned $available_variations I have all the variations.
I am given the variation_id, and I do not have the knowledge of the name of the attribute, which in this case is country-of-origin, so how do i retrieve the attribute values, which are Hong Kong and Singapore in this case?
Below is the dump of above $available_variations,
[18-Mar-2014 17:04:20 UTC] Array
(
[variation_id] => 2968
[attributes] => Array
(
[attribute_pa_country-of-origin] => hong-kong
)
[image_src] =>
[image_link] =>
[image_title] =>
[image_alt] =>
[price_html] => <span class="price"><span class="amount">SGD$15</span></span>
[availability_html] =>
[sku] =>
[weight] => kg
[dimensions] =>
[min_qty] => 1
[max_qty] => 0
[backorders_allowed] =>
[is_in_stock] => 1
[is_downloadable] =>
[is_virtual] =>
[is_sold_individually] => no
)
[18-Mar-2014 17:04:20 UTC] Array
(
[variation_id] => 2969
[attributes] => Array
(
[attribute_pa_country-of-origin] => singapore
)
[image_src] =>
[image_link] =>
[image_title] =>
[image_alt] =>
[price_html] => <span class="price"><span class="amount">SGD$12</span></span>
[availability_html] =>
[sku] =>
[weight] => kg
[dimensions] =>
[min_qty] => 1
[max_qty] => 0
[backorders_allowed] =>
[is_in_stock] => 1
[is_downloadable] =>
[is_virtual] =>
[is_sold_individually] => no
)
I know this is old but just incase someone needs this in the future and comes across this post, the correct way is.
echo $available_variations[0][attributes][attribute_pa_country-of-origin];
echo $available_variations[1][attributes][attribute_pa_country-of-origin];
I trying to create a query to get some news from category A,B,C
I wont a article which is in all categories.
Array
(
[post_type] => catalog
[order] => DESC
[orderby] => date
[status] => publish
[paged] => 1
[tax_query] => Array
(
[0] => Array
(
[taxonomy] => catalog_category
[field] => id
[include_children] => 1
[operator] => AND
[terms] => Array
(
[0] => 12
[1] => 17
[2] => 43
)
)
)
)
If I use "operator" "IN" I get all articles if I use "AND" I get none results.
List of my cats and articles:
As you can see, I have only 1 article in all 3 categories.
What is my mistake?
Your query seems fine but not sure what is wrong, anyways, as an alternative you may give it a try to get all posts (custom post type = catalog) which belongs to all three categories in (a, b and c), not less/more but exact match of all categories.
$cat_Ids = array();
// get id from each category name
foreach(array('a', 'b', 'c') as $cat) {
$cat_Ids[] = get_cat_ID($cat)
}
$args = array(
'post_type' => 'catalog', // <-- post type is 'catalog', not 'news', right ?
'category__and' => $cat_Ids,
'orderby' => 'date',
'order' => 'DESC',
'status' => 'publish'
);
$query = new WP_Query($args);
I'm having an issue with the get_terms() function.
If I use:
<?php
$terms = get_terms( 'location' );
print_r($terms);
?>
I get an array back:
Array ( [0] => stdClass Object ( [term_id] => 8 [name] => Aberdare [slug] => aberdare [term_group] => 0 [term_taxonomy_id] => 8 [taxonomy] => location [description] => [parent] => 7 [count] => 1 ) [1] => stdClass Object ( [term_id] => 10 [name] => Aberdeen [slug] => aberdeen [term_group] => 0 [term_taxonomy_id] => 10 [taxonomy] => location [description] => [parent] => 9 [count] => 14 ) [2] => stdClass Object ( [term_id] => 17 [name] => Aberdeenshire [slug] => aberdeenshire [term_group] => 0 [term_taxonomy_id] => 17 [taxonomy] => location [description] => [parent] => 9 [count] => 41 ) [3] => stdClass Object ( [term_id] => 1203 [name] => Aberdour [slug] => aberdour [term_group] => 0 [term_taxonomy_id] => 1203 [taxonomy] => location [description] => [parent] => 446 [count] => 1 );
But if I try and get the terms with the parent of of any number of child_of the array comes back empty.
<?php
$terms = get_terms( 'location', array('parent' => 9) );
print_r($terms);
?>
I get this:
Array ( )
Does any one know what i'm doing wrong?
Thanks
Pete
Ok I solved the issue.
Was a bit strange really. All my terms were added via a script using the wp_insert_term function. When I went to the edit-tags.php?taxonomy=location page in the dashboard could only see the top three terms in the list on the right, but I could see the others in he term cloud on the left.
I then went into one of the terms and saved it and they all appeared in the list on the right hand side and also in my array.
I'm guessing their must of been some sort of caching on the terms list and it needed me to save one through the dashboard in order to see the hierarchy.
A strange one I must admit.
Pete
The hierarchy is cached, and is not invalidated automatically after wp_insert_term. You can call
delete_option("{$taxonomy}_children");
manually to force a regeneration on next access to the hierarchy.
I have this output:, and I want to get to "Center".
[field_affiliation] => Array(
[und] => Array(
[0] => Array(
[tid] => 30
[taxonomy_term] => stdClass Object(
[tid] => 30
[vid] => 2
[name] => Center
Can I use this method?
$affiliation=$node->field_affiliation['und']['0']['value']['taxonomy_term']['name'];
or how can I use:
drupal_array_get_nested_value(); - I cannot understand the documentation
Try this it will work
as the name is under the object 'taxonomy_term'
$affiliation=$node->field_affiliation['und']['0']['taxonomy_term']->name;
The reason I need to do this is because we are turning our CMS over to a client and we need them to follow the rules but we can't just change the value outright as there is content in the system that breaks the max length rules for some fields and we don't want them to get chopped. So going ahead we just want to target all new content by targeting the new content form (node-form). I currently have a hook that successfully changes the max value for the title below:
function myForm_form_alter(&$form, &$form_state, $form_id) {
if($form['#id'] == 'node-form') {
$form['title']['#maxlength'] = 30;
}
}
I need to add one for a field named "field_feature_desc". I printed the form info to the screen and here is the info I received for that field:
[field_feature_desc] => Array
(
[field_name] => field_feature_desc
[type_name] => article
[display_settings] => Array
(
[weight] => 11
[parent] =>
[label] => Array
(
[format] => above
)
[teaser] => Array
(
[format] => default
[exclude] => 1
)
[full] => Array
(
[format] => default
[exclude] => 1
)
[4] => Array
(
[format] => default
[exclude] => 1
)
[2] => Array
(
[format] => default
[exclude] => 0
)
[3] => Array
(
[format] => default
[exclude] => 0
)
)
[widget_active] => 1
[type] => text
[required] => 0
[multiple] => 0
[db_storage] => 0
[module] => text
[active] => 1
[locked] => 0
[columns] => Array
(
[value] => Array
(
[type] => text
[size] => big
[not null] =>
[sortable] => 1
[views] => 1
)
)
[text_processing] => 0
[max_length] =>
[allowed_values] =>
[allowed_values_php] =>
[widget] => Array
(
[rows] => 5
[size] => 60
[default_value] => Array
(
[0] => Array
(
[value] =>
[_error_element] => default_value_widget][field_feature_desc][0][value
)
)
[default_value_php] =>
[label] => Feature Description
[weight] => -3
[description] => Description text in the feature area on the homepage, if applicable
[type] => text_textfield
[module] => text
)
)
If you have an idea how i would code for this additional field it would be much appreciated. I've been trying the following:
$form['field_feature_desc']['max_length'] = 70;
$form['field_feature_desc']['columns']['value']['length'] = 70;
Sorry if there is already an answer for this question, I looked all over for one and couldn't locate one.
I discovered an array outside of the one i was working with. So the code that did it was:
$form['#field_info'] = array(
'field_feature_desc' => array(
'max_length' => 70,
),
);
Or a shorter version is:
$form['#field_info']['field_feature_desc']['max_length'] = 70;