Please add option to create goods labels as link.

Thank you!

Comments

subhojit777’s picture

Category: Task » Feature request
Related issues: +#2363335: Please print product price total per each line item?
subhojit777’s picture

In any case you can do this by overriding the templates.

anikitin35’s picture

How I can print a product title as link on the same product?

subhojit777’s picture

You will find this code in dc_ajax_add_cart.module

function template_preprocess_dc_ajax_shopping_cart(&$variables) {
...
    foreach ($line_item_list as $line_item) {
      if (property_exists($line_item, 'commerce_product')) {
        $product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);

        if (variable_get('dc_ajax_add_cart_update_quantity', 0) == 1) {
          $updateable_quantity = drupal_get_form('dc_ajax_add_cart_update_quantity_' . $line_item->line_item_id, $line_item);
          $quantity = drupal_render($updateable_quantity);
        }
        else {
          $quantity = intval($line_item->quantity);
        }

        $row[] = array(
          array('data' => $quantity, 'class' => array('quantity')),
          array('data' => $product->title, 'class' => array('name')),
          array('data' => $product_prices[$product->product_id], 'class' => array('price')),
          array(
            'data' => l(variable_get(DC_AJAX_ADD_CART_REMOVE_CART, 'link') == 'link' ? t('Remove from cart') : $image_remove_cart,
            'remove-product/nojs/' . $line_item->line_item_id,
            array(
              'attributes' => array(
                'class' => array('use-ajax'),
              ), 'html' => TRUE)), 'class' => array('remove-from-cart')),
        );
      }
    }
...
}

array('data' => $product->title, 'class' => array('name')), this is the code that generates product title. You can use this code in your custom theme template preprocess, and override it there, and then use thise code to generate the cart markup:

    $variables['products_list_html'] = theme('table', array(
      'header' => $header,
      'rows' => $row,
      'attributes' => array(
        'class' => array('ajax-shopping-cart-table'),
      ),
      'sticky' => FALSE,
    ));
subhojit777’s picture

I am leaving it opened because I would like to add this in the module itself. Patches are welcome.

subhojit777’s picture

Status: Active » Needs work
Samaella’s picture

I used to query the database:

<?php
function template_preprocess_dc_ajax_shopping_cart(&$variables) {
...
foreach ($line_item_list as $line_item) {
...
$id = $product->product_id;
$id_node = db_select('field_data_field_product', 'n')
				  ->fields('n', array('entity_id'))
				  ->condition('n.field_product_product_id', $id)
				  ->execute()
				  ->fetchField();
		
$node_url = url('node/' . $id_node, array('absolute' => TRUE));

$row[] = array(
...
array('data' => '<a href="'.$node_url.'">'.$product->title.'</a>', 'class' => array('name')),
...
);
}

...
}
?>
subhojit777’s picture

Issue tags: +Novice
subhojit777’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev