Solved

drupal7 ubercart. Adapting block display of shopping cart

Posted on 2013-01-27
10
1,732 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now