I can not understand why view block is not shown for anonymous users.

here is the code:

function mymodule_cart_block_view($delta) {
  global $user;
  // Prepare the display of the default Shopping Cart block.
  if ($delta == 'photoprint_cart') {
    // Default to an empty cart block message.
    $content = theme('commerce_cart_empty_block');

    // First check to ensure there are products in the shopping cart.
    if ($order = commerce_cart_order_load($user->uid."_photoprint")) {
      $wrapper = entity_metadata_wrapper('commerce_order', $order);

      // If there are one or more products in the cart...
      if (commerce_line_items_quantity($wrapper->commerce_line_items, commerce_product_line_item_types()) > 0) {
        // Build the variables array to send to the cart block template.
        $variables = array(
          'order' => $order,
          'contents_view' => commerce_embed_view('photoprint_cart_block', 'defaults', array($order->order_id), $_GET['q']),
        );

        $content = theme('commerce_cart_block', $variables);
      }
    }

    return array('subject' => t('Photoprint Shopping cart'), 'content' => $content);
  }
}

code is copied from commerce cart . for logged users it works great.. i almost setted up my multicart logic. but have this nasty bug with anonymous.

i debugged this function and have some results. commerce_embed_view function is executed, and variable $variables contain this:

array(2) { ["order"]=> object(stdClass)#532 (19) { ["order_number"]=> string(2) "23" ["revision_id"]=> string(3) "117" 
["revision_uid"]=> string(1) "0" ["mail"]=> string(0) "" ["status"]=> string(4) "cart" ["log"]=> string(33)
 "Created as a shopping cart order." ["revision_timestamp"]=> string(10) "1380951560" ["revision_hostname"]=> string(14)
 "85.196.243.233" ["data"]=> array(0) { } ["order_id"]=> string(2) "23" ["type"]=> string(16) "photoprint_order" ["uid"]=> 
string(1) "0" ["created"]=> string(10) "1380944188" ["changed"]=> string(10) "1380951560" ["hostname"]=> string(14) 
"85.196.243.233" ["commerce_line_items"]=> array(1) { ["und"]=> array(12) { [0]=> array(1) { ["line_item_id"]=> string(3) "336" } 
[1]=> array(1) { ["line_item_id"]=> string(3) "337" } [2]=> array(1) { ["line_item_id"]=> string(3) "338" } [3]=> array(1) {
 ["line_item_id"]=> string(3) "339" } [4]=> array(1) { ["line_item_id"]=> string(3) "340" } [5]=> array(1) { ["line_item_id"]=> 
string(3) "341" } [6]=> array(1) { ["line_item_id"]=> string(3) "342" } [7]=> array(1) { ["line_item_id"]=> string(3) "343" } 
[8]=> array(1) { ["line_item_id"]=> string(3) "344" } [9]=> array(1) { ["line_item_id"]=> string(3) "345" } [10]=> array(1) { 
["line_item_id"]=> string(3) "346" } [11]=> array(1) { ["line_item_id"]=> string(3) "347" } } } ["commerce_order_total"]=> 
array(1) { ["und"]=> array(1) { [0]=> array(3) { ["amount"]=> string(4) "1200" ["currency_code"]=> string(3) "USD" ["data"]=> 
array(1) { ["components"]=> array(1) { [0]=> array(3) { ["name"]=> string(10) "base_price" ["price"]=> array(3) { ["amount"]=> 
int(1200) ["currency_code"]=> string(3) "USD" ["data"]=> array(0) { } } ["included"]=> bool(true) } } } } } } 
["commerce_customer_billing"]=> array(0) { } ["rdf_mapping"]=> array(0) { } } ["contents_view"]=> string(184) "
" }

that is, all 12 Line Items somehow got there .. but for some reason contents_view is empty .. very annoying. what could be wrong? why its not rendered?

also i can preview this cart in admin backend. in views and in store shopping carts list.

Comments

rszrama’s picture

rszrama’s picture

Issue summary: View changes

additional info