First of all - Thank you for the plugin.... it's covers exactly what we need for our website

I'm however coming across a PHP error -
EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 744 of C:\xampp\htdocs\sites\all\modules\contrib\entity\includes\entity.wrapper.inc).

This occurs when I've added a product with DA Entity rules applied and then visit a domain that the entity isn't ticked to display in. If this occurs on a node level it simply doesn't display that particular node on that domain... instead of throwing this error.

What can I do to get around?

Comments

harings_rob’s picture

I'm having the same issue.

ben.collier’s picture

Just to clarify - this happens when adding a commerce entity to my cart and then change domains

delta’s picture

can you try to explain me the exact step to reproduce it.
As far as i understand:

1 - You have a product assigned on domain 1
2 - you visit the domain 1 and add the product to the cart
3 - you visit the domain 2, BOOM errors, that's right ?

I will need your two domains configuration (is just subdomain right ?).
are you logged in ? if yes what are the user permission (just permission of this module and d.a. if any)
The version of commerce you are using..
The entity types of drupal commerce that you have enabled with D.A Entity ?

thanks

ben.collier’s picture

thanks for the reply!

Your 1,2,3 steps are correct

- Yep both sub domains
- I am not logged in (anonymous user)
- Commerce version 7.x-1.4
- Entity type is a custom product type

Let me know if you need anymore info

delta’s picture

I try with the latest stable release of drupal, domain access & entities, commerce.
I try the 1 2 3 steps and didn't reproduce your issue.
- on domain 1, i add a product in my cart, this product is accessible only on domain 1.
- I switch on domain 2, I see my cart empty, i see the product display but I didn't have the add to cart widget because the product is not accessible.
@ben.collier, @easycombvba :
- Can you try with a simple drupal commerce configuration and domain access & DA Entities enabled and tell me if you reproduce this issue.
- On your existing conf : can you try to deactivate domain access entity module and see if you reproduce this issue.

harings_rob’s picture

Hi,

The issue from my side is gone as soon as i disable domain entity (this module itself).

I receive the error when logged in and viewing my frontpage for example.

All my modules are up to date. But for extra information here are some extra modules is use. Perhaps we can find a relation between the 3 sites with issues.

Entity Translation
Domain Menu Access
Domain Views
Subfolders Domain
I10n etc..

harings_rob’s picture

Excuse me, I wanted to start debugging and noticed my error is slightly different:

EntityMetadataWrapperException: Unable to get the data property status as the parent data structure is not set. in EntityStructureWrapper->getPropertyValue() (regel 442 van /home/.../domains/.../public_html/profiles/commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc).

delta’s picture

ok i reproduce the issue with cross subdomain cookie enabled in settings.php and i found the problem come from the module commerce_product reference.

you share the same commerce order (cart) on both domains for one user. you create a line item that reference a product accessible on one domain only.
at this point the field commerce product reference try to load the commerce_product and failed to do it.

You have two solutions:

you just want to separate editorial product by domain :
don't activate domain entity on commerce_product entity, and use domain access on the node that display the product instead.

OR
You want a commerce store by domain:
you should activate domain entity on commerce order entity and commerce line item, with a default value on "current domain", so the user have different cart on each store.

You cannot show an entity when a user has no the permission to see it.

I think you should report this error to the commerce project too, as this error happen in commerce_product_reference module.

harings_rob’s picture

don't activate domain entity on commerce_product entity, and use domain access on the node that display the product instead.

Explain this to me? I've been trying this solution for a few days instead of using domain entity.

delta’s picture

Have you already use domain access with normal node ?

With drupal commerce, to show a commerce_product (add to cart widget) to the user you have to create a node that display it.

Use domain access on that node.

harings_rob’s picture

This is how it currently is setup. (like you said).

But there is no way it works becouse:

Search api uses the entity
Views uses the search api

So the catalog is displaying all the products, when clicked on a product you get 'no access'.

Tried to get domain access into my views / or into my search api, but with no success.

delta’s picture

in that case maybe your last chance is to alter the way your product are indexed with search api (look for a display node that reference this product grab is domain values and index it in a custom index field, then alter the search request with a criteria on that field depending on the domain).

if you don't want to separate the cart of your users by domain, you can not use this module, because of the way entity are referenced in database, and some module presume that an entity referenced will be always accessible by it's parent. You need the access rules to be consistent at each level of reference.

You can use this module with drupal commerce to make one store (cart/checkout) by domain.

delta’s picture

you can also index only the product node ? why don't you do that ?

i just realize it's what your doing... so am i on a shop...

as i said before you have to alter the indexation and the request

Something like this may do the trick:

/**
 * Implements hook_apachesolr_query_alter().
 */
function MYMODULE_apachesolr_query_alter(&$query) {
  $domain = domain_get_domain();
  if (empty($domain)) {
    return;
  }
  $query->addFilter('im_domain', $domain['domain_id']);
}

/**
 * Build the documents before sending them to Solr.
 */
function MYMODULE_apachesolr_index_document_build_node(ApacheSolrDocument &$document, $node, $env_id) {
	$node = node_load($node->nid);
	if (!empty($node->domains)) {
		foreach($node->domains as $key => $domain) {
			$document->addField('im_domain', $domain);
		}
	}
}
delta’s picture

Category: bug » support
Priority: Major » Normal
delta’s picture

Title: EntityMetadataWrapperException: » how to configure this module with Drupal commerce and these referenced entities
harings_rob’s picture

Okay, that's for the apachesolr.

I'm 'currently' using the default database search.

Added the following code:

/**
* Implements hook_entity_property_info_alter().
*
* Adds an entity property for the domain access of the node.
*/

function commerce_ds_entity_property_info_alter(&$info) {

  $properties = &$info['node']['properties'];

  $properties['commerce_ds_domain_access'] = array(
    'label' => t('Domain Access Information'),
    'description' => t('The domains to which the node is published.'),
    'type' => 'list<integer>',
    'getter callback' => 'commerce_ds_get_domain_info',
  );
}

function commerce_ds_get_domain_info($data, array $options, $name, $type, $info) {
  return (!empty($data->domains) ? $data->domains : NULL);
}

/**
* Implements hook_search_api_query_alter().
*
* Adds a filter for the current domain.
*/

function commerce_ds_search_api_query_alter(SearchApiQueryInterface $query) {

  $domain = domain_get_domain();
  $query->condition('commerce_ds_domain_access', $domain['domain_id']);
      
}

But this seems not to work either.

If i create a normal view with my nodes everything works great but.. no optimization, no facets (unless i manually create them in views and that's a nogo). I plan on setting up apachesolr search, but not while testing.

Some extra information:

It gets filtered correctly, but my paging is messed up.

For 25 products, i have 13! pages.

In my views its setup to have 15/page. (so max 2 pages in this case).

Also the results show 2 or 3 products and then a next button (like there are invisible? nodes wich are taken into views, but are not being displayed).

Strange..

Fixed it: http://i.imgur.com/VNv9Aui.png

However i tried this before these are the steps:

Search index -> disable the one provided by drupal commerce
Add one and make it index the nodes! not commerce product.

Recreate views and configure them like the original one.

Set the query options you see in the screenshot above.

Done.

agoradesign’s picture

You want a commerce store by domain:
you should activate domain entity on commerce order entity and commerce line item, with a default value on "current domain", so the user have different cart on each store.

A customer would like to have 3 stores in one installation. So I've played around a bit with Domain Access to find out, if we can accomplish this.

In order to separate the orders by store, I've followed your advice and activated Domain Entity on both the orders and commerce line items, auto-assigning the current domain. Interestingly, the following things happened:

* all the existing orders were "domainized" fine
* any order that was created afterwards, is broken

In the order admin, the orders are listed, but do not have any operations (view, edit,...) to click. When click on the order number to view it, it doesn't show up - 404 error. (Logged in with uid 1!!)

When I manually load an order in code by calling commerce_order_load() and show it with dpm(), the good ones are loaded correctly, the new broken ones are empty, so the load command returns FALSE (or NULL or any other empty value), without throwing an error.

I've looked into the database, and all what I saw seemed to be fine, seeing no difference between working and broken orders.

When I now remove Domain Entity from Commerce Order, everything is fine again. So the not the entities themselves are broken, only something with the domain restriction went wrong.

Update

I've found another important detail, coming closer to the root of the problem:
I've activated Domain Entity on the Commerce Order again, but with an important difference to the last time: at the first time, I was activating it while being on the main domain. Now, I did it on one of the other domains and every existing order is broken now - no matter on which domain I try to access one of them...

So, my conclusion is: I've found a bug. It only works on the main domain, not on the sub domains...

delta’s picture

When you use this module with a user that have the permission "access entities affiliate on assigned domains"

You must assign the good domain to the user in user/%/edit

When you are logged in with a user that have this permission, the entities became accessible only when there are assigned to the same domain that the logged in user have.

you must assign the user to the good domain(s), e.g. he can edit.

Please see read small notice instructions on the project page of this module :

Enable domain_entity
- Go to admin/structure/domain/entities
- Enable domain on entity types, choose the behavior widget you want for each bundle (existing content of your website will be assigned to the default bundle domain value)
- For site administrator roles that you want to allow to see multiple domain entities on one domain (only in administration path) :

Create a user
Add a role to the user with the permission "access entities affiliate on assigned domains"
Assign the user to the domain(s) he can access ("Affiliate editor options" in admin/people)

This behavior is only for the administration paths. and for the user with that permission (uid 1 also..)
This is to give you the ability to create role for commerce things and a user for each domain that see only the relevant entities in admin paths when is connected.

For the commerce orders default view, it seems that you have to edit it and disable sql rewriting (open your views -> go in advanced settings pane -> query settings),
if you don't want to disable sql rewriting, you can add manually a view filter on the field that hold the domain(s) id.

agoradesign’s picture

Thank you very much! That really solved my problem :)

I thought that uid 1 always sees everything... like the Domain Access module does with nodes

pedrosp’s picture

Issue summary: View changes

I just bumped twice with the same problem in the past few weeks... #shameonme
For mental health sake, I think it is necessary either to override the uid 1 behaviour in the code to see everything as normally expected,
or to highlight in the readme/ install instructions that uid 1 (generally for admin and test purposes) has to be assigned on all domains (specially the new ones).

Paul Lomax’s picture

Disabling query re-writing in the view solved my problem! Is there a technical explanation as to why this is? Spent ages debugging it.

I found switching the query_alter off for UID 1 helped immensely, it just seems to behave more like Domain Access does. You can use this in a custom module if it helps anyone.

function MYMODULE_init() {
  global $user, $conf;
  if ($user->uid == 1) {
    $conf['domain_entity_bypass_access_conditions'] = true;
  }
}
fox_01’s picture

i cant get domain_entity working with commerce kickstart. i've done all things adviced here but still get the error while visiting the product

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 736 of /httpdocs/profiles/commerce_kickstart/modules/contrib/entity/includes/entity.wrapper.inc).

#21 does "fix" it temporarily but this is only for dev purposes not really for production

Does anyone got this working?

The workarround to apply domain access on node level is possible the bug still exists further as i think.

deltaag’s picture

This solution worked for me for 'All Products' page regarding #11 to #16, using commerce kickstart 7.x-2.27 and Domain Access 7.x-3.12:
Edit views Display Products (the one makes /products page)
Advanced > Other > Query settings: activate “Additional access checks on result entities” and save it.