Solved

drupal7 ubercart. Adapting block display of shopping cart

Posted on 2013-01-27
10
1,753 Views
Last Modified: 2013-01-29
There is an article by Dylan Tack on:

Tiny Cart Block for Ubercart

on a Tiny Cart Block for Ubercart. It does exactly what I want but it is designed for drupal 6.
There is a comment asking the author if it works with drupal 7 and ubercart 3 (I have 7.x-3.3) but he has not produced a version for drupal 7.

I have tried:

1. Creating a folder in my sites/all/modules folder and called it tiny_cart
2. Have created a file called tiny_cart.module in this folder and copied this into it

<?php
/**
 * Implementation of hook_block().
 */
function tiny_cart_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0] = array(
        'info' => t('Micro-sized cart block for page header.'),
        // This block cannot be cached, because anonymous
        // sessions can have differing cart contents.
        // To improve this, see drupal.org/project/uc_ajax_cart
        'cache' => BLOCK_NO_CACHE,
      );
      return $blocks;
    case 'view':
      if ($item_count = uc_cart_get_total_qty()) {
        $block = array();
        $block['subject'] = '';
        $block['content'] = theme('image',
          drupal_get_path('module', 'uc_cart') .'/images/cart-full.png');
        $block['content'] .= format_plural($item_count,
          'My cart: 1 item', 'My cart: @count items');
        $block['content'] = l($block['content'], 'cart', array('html' => TRUE));
        return $block;
      }
      break;
    }
}

but it doesn't appear in the list of blocks. Only the standard Shopping Cart appears. I assume if it worked if would appear as tiny_cart.
How can I get it to work?
0
Comment
Question by:bogorman
  • 6
  • 4
10 Comments
 
LVL 17

Expert Comment

by:nanharbison
ID: 38826361
Did you create the tiny_cart.info file? That is the one that makes it show up in the list of modules. Look at the info file for another module to see how it is formed. It is similar to the theme.info file.You list the name of the module, and which core it goes with, a description, and which other modules it is dependent on, and the other files included in the module, etc.
0
 

Author Comment

by:bogorman
ID: 38826531
Hi nanharbison,
Have tried to follow your advice and have put the following in the info file:

name = Tiny Cart
description = Provides a mini shopping cart for navigation block
core = 7.x
package = Ubercart


but I have obviously not done it correctly as I get the following errors:


   
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in system_sort_modules_by_info_name() (line 949 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Warning: uasort() [function.uasort]: Array was modified by the user comparison function in system_modules() (line 800 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).
    Notice: Undefined index: name in _system_modules_build_row() (line 982 of /home/faithmov/public_html/drupal/modules/system/system.admin.inc).


When I look at the modules list, it appears in a new section headed Ubercart but only the description shows. There is a box under Enabled but no description.

Where have I gone wrong?
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 38826554
Did you set dependencies, like:
dependencies[] = ubercart
?
I am not sure what modules this code needs to work, but maybe that is the cause of the errors.
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:bogorman
ID: 38828175
Hi,
Thanks for help so far.
My info file reads:

name = Tiny Cart
description = Provides a mini shopping cart for navigation block
core = 7.x
package = Ubercart - core
dependencies[] = uc_order
dependencies[] = uc_product

and my module file:

<?php
/**
 * Implementation of hook_block().
 */
function tiny_cart_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {
    case 'list':
      $blocks[0] = array(
        'info' => t('Micro-sized cart block for page header.'),
        // This block cannot be cached, because anonymous
        // sessions can have differing cart contents.
        // To improve this, see drupal.org/project/uc_ajax_cart
        'cache' => BLOCK_NO_CACHE,
      );
      return $blocks;
    case 'view':
      if ($item_count = uc_cart_get_total_qty()) {
        $block = array();
        $block['subject'] = '';
        $block['content'] = theme('image',
          drupal_get_path('module', 'uc_cart') .'/images/cart-full.png');
        $block['content'] .= format_plural($item_count,
          'My cart: 1 item', 'My cart: @count items');
        $block['content'] = l($block['content'], 'cart', array('html' => TRUE));
        return $block;
      }
      break;
    }
}

I have installed the tiny_cart folder IN THE UBERCART FOLDER.

The module appears on the module page under Ubercart - core.  Have enabled it. It is not listed on the permissions page.

Problem is that it does not appear on the blocks page.  I assume that this is due to some differences in the code for drupal 7 and drupal 6, though there are no errors. Can you suggest how I can get it running.
Brian
0
 
LVL 17

Accepted Solution

by:
nanharbison earned 500 total points
ID: 38831819
I am not sure you should put this module inside another module. Did you try putting it it in its own folder in the sites/all/modules folder?
This might help you, how to convert a D6 module to D7.
http://drupal.org/node/224333
0
 

Author Comment

by:bogorman
ID: 38832224
Thanks.
Have moved it to sites/all/modules but it still doesn't appear on the blocks page. Have run update.php and flushed the caches.
Thanks anyway, nanharbison. Will study the upgrade instructions but am beginning to think it might be easier to try and modify the existing shopping cart block. Have assigned the points.
Regards
Brian
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 38832380
Don't you have to find the cart in site configuration, and create it and then it shows up in the blocks? that's how some other modules work that end up in blocks. Like the dynamic display block, you have to create an instance first and then it shows up in the blocks.
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 38832383
Oh, and thanks for the points.
0
 

Author Comment

by:bogorman
ID: 38832425
It's not listed under Configuration. Am really not sure.
In fact the "standard" cart looks quite good and I will probably keep to that.
Sorry, have taken site offline for the time being until I get it right, otherwise I could show you.
0
 
LVL 17

Expert Comment

by:nanharbison
ID: 38832763
No problem, good luck with this project!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
The viewer will learn how to count occurrences of each item in an array.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question