Tags/topics: 
1
Answers
Vote up!
0
Vote down!

How to replace the standard Add to Cart block?

Hi,

I used VBO in order to assemble a view showing fields (such as size, stock, price, add to cart quantity) of all product variations of a product. This allows me to select the quantities to order for all variations (different sizes and colors) of the same product remaining in the same page and to add all of them to the shopping cart.

So far, no problems. Now I'm struggling with an apparently "simple" problem: how can I insert this view in my product display page in place of the default "Enter quantity + Add to cart" block?

Sorry for the possibly silly question, but I'm stuck.

Thanks in advance to whomever will be so kind as to shed some light.

Ettore

Asked by: epaolillo
on October 23, 2013

Comments

You can create a node template called node--product_display.tpl.php (product_display is the name of the content type to display products if you named yours different replace product_display with your content type name) Just copy the node.tpl.php file and rename it.

Upload the new file and clear your cache. Now you can make changes to this file. You can remove element like content and then print them with something like

<?php
 
print render($content['field_product_rating']);
?>
This will print a filed for 5 star module called product rating.

If the new file changes are not being accepted add this to your template.php file in your themes directory. Replace YOURTHEME with the name of your theme for example bluemarine.

function YOURTHEME_preprocess_page(&$variables, $hook) {

   // Page template suggestions based off of content types

   if (isset($variables['node'])) {

                $variables['theme_hook_suggestions'][] = 'page__type__'. $variables['node']->type;

                $variables['theme_hook_suggestions'][] = "page__node__" . $variables['node']->nid;

   }

  

   // Page template suggestions based off URL alias

   if (module_exists('path')) {

    $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));

    if ($alias != $_GET['q']) {

      $template_filename = 'page';

      foreach (explode('/', $alias) as $path_part) {

        $template_filename = $template_filename . '__' . $path_part;

        $variables['theme_hook_suggestions'][] = $template_filename;

      }

    }

  }

  

}

Now once you structure your template you can also create a custom regions and used those in the template to insert blocks into it. To create a custom region add it to your THEMENAME.info file like this, You can name it whatever you want.

regions[product_buy_form]    = Product Buy Form

Then in your node--product_display.tpl.php file add this

<?php print render(block_get_blocks_by_region('product_buy_form')); ?>

So now you can take the VBO block and insert it into the new region.

Hopefully that makes some sense.

- analog andy on October 28, 2013

Sorry for the late acknowledge of you suggestions: I hadn't checked the blog for a few days!
Thank you very much for your hints. I will try your approach as well. In the meantime I have solved my problem by installing the Viewfield module. This module allows to insert a view in a node by adding a field that references a view. I have added this field to my product content type and through it made a reference to the VBO view. Nevertheless I will experiment also with your approach which appears more versatile.

- epaolillo on November 4, 2013

1 Answer