Jump to content

Add product category in basket?


markThomas

Recommended Posts

I searched around, could not find this in the forums...

 

I would like to have the product category show up in the shopping basket, as well as the digital download documents. You would see the category listed above the product for each of the purchases. 

 

Is there a way to code this or perhaps a setting?

 

Thanks in advance. 

Link to comment
Share on other sites

In both the skin's Side-Basket and in the View Cart page (checkout), only the product's main category's cat_id is currently known. We will need to fetch the data from the Cubecart_category table to show the name of the category.

 

Also, it is only the Main Category assigned to the product data array -- CubeCart does not have the code to remember what the actual category being viewed was when the product was added to the basket. If that's what you need to know, then we need a different approach.

 

Let's look at >this post and adjust it so that we can have what we need.

$this->getCategoryData($product['cat_id']);$product['cat_name'] = $this->_categoryData['cat_name'];

 

The skin template file box.basket.php and content.checkout.php will be using $item for each item in the list.

 

Could you better explain what you want to see in the "digital download documents"?

Link to comment
Share on other sites

As I understand it the Main Category is the primary category that the product is assigned to. This is the category that we are trying to show at the basket and in the email confirmations. Currently, only the product is shown in the basket. 

 

In the digital downloads, the product is the only item listed. Because the document being downloaded (= product ) belongs to a particular association (= category ), we want to have the product's primary category listed on the line above the product.

 

EX:

-----------------------------------

Thank your for your purchase. 

 

Gilbert Home Owners Association   <- primary category, currently not shown in basket or reciepts

Section 2314 Special Assessments document   <- product purchased

 

will be available for download ....

-------------------------------------

 

Hope this makes sense.

You have provided another link, thank you for that. However, not sure what I am looking for. 

Link to comment
Share on other sites

The link mentions the file and line numbers to edit (line numbers may have changed for the latest version of CubeCart since that was posted), and the reasoning for the edits.

 

The edits should make available the needed data to you. If you need assistance on how to program the HTML for the sidebasket, checkout, and the email templates, let us know.

Link to comment
Share on other sites

Check me on this...
 
the previous link said

 

 

However, CubeCart does not make available any properties concerning the category itself to this template. We will add what we need.

 

In the file /classes/catalogue.class.php, near line 181, find the function displayProduct(). About 25 lines down, find $this->productAssign($product);

 

Using the blank line after that, add:

$this->getCategoryData($product['cat_id']);$product['cat_parent_id'] = $this->_categoryData['cat_parent_id'];

 

In the template code, you now have $PRODUCT.cat_parent_id available.

 

And your last code snippet suggested :

 

 

Let's look at this post and adjust it so that we can have what we need.

$this->getCategoryData($product['cat_id']);$product['cat_name'] = $this->_categoryData['cat_name'];

 

Putting things together:

 

Find the function displayProduct(), where $this is assigned. 

Empty line next paste - $this->getCategoryData($product['cat_id']);$product['cat_name'] = $this->_categoryData['cat_name'];

 

This should give the template code access to : $PRODUCT.cat_name

 

Finally, I did not understand your reference here:  The skin template file box.basket.php and content.checkout.php will be using $item for each item in the list. ???

 

Thank you so much for your expertise on this.

It will save a great deal of time getting this to show the category automatically instead of backtracking into all the products and pasting the category name into the product description. 

 

M

Link to comment
Share on other sites

For template code, CubeCart uses the Smarty template system. Here is how variables work in Smarty:

 

$PRODUCT is a variable which can hold a string, a number, an array of strings, numbers, or more arrays. If it's an array, to get to a particular array element of $PRODUCT, the syntax is: $PRODUCT.element_name.

 

Previously, the CubeCart code gathers up all pertinent data regarding a product. In fact, our edit in displayProduct() gathered up some additional data that wasn't there before, the cat_name. We assigned the cat_name to the array $product giving the array element name of ['cat_name'].

 

Later in the CubeCart code, the array $product was itself stacked onto an array of $products. $products, in turn, is given to the Smarty variable $ITEMS.

 

Let's look at the HTML in content.checkout.php. Find this line:

{foreach from=$ITEMS key=hash item=item}

 

So, $ITEMS contains an array, which the CubeCart code had as $products, and each element in that array is itself an array, which for this template, holds a product's set of data in the Smarty variable $item.

 

Find this line in the template file:

<p><a href="{$item.link}" class="txtDefault"><strong>{$item.name}</strong></a> {if !empty($item.product_code)}- {$item.product_code}{/if} {if $item.base_price_display}({$item.base_price_display}){/if}</p>

Notice how $item is used here. So, continuing to use $item as the name of the array, we then use $item.cat_name as the means to show the name of the category for this product.

 

The new line of HTML in the content.checkout.php file would be:

<p><strong>{$item.cat_name}</strong></p>

The skin template file box.basket.php also uses $item as the name of the array holding each product's set of data.

 

As far as the Digital Download email is concerned, we need to do some more work. CubeCart might use a different function to gather the product's data. We will work on that next.

Link to comment
Share on other sites

Good explanation, thank you.

I have located everything, made some backups, made the changes discussed above. 

 

Unfortunately, not seeing the data. 

I am seeing the HTML markup, but the containers are empty. 

I will examine the catalogue.class.php code again to see if I missed something, and post again. 

 

M

Link to comment
Share on other sites

So what we will do is to use the more universal function, getProductData() in the catalogue.class.php file. This is near line 461.

 

About 44 lines later, find:

$this->getProductPrice($product, $quantity);

Change that line to this:

$this->getProductPrice($product, $quantity); $this->getCategoryData($product['cat_id']);$product['cat_name'] = $this->_categoryData['cat_name'];

Now the cat_name should be available in the sidebasket and checkout templates.

Link to comment
Share on other sites

That was it!

Yes, the category name now appears in both baskets, the small and the large. 

Any chance that access to the Category name will follow to the email confirmation?( I have another thread started on that one. )

 

Thank you for the double check on the code. This will make some office folks happy. 

Link to comment
Share on other sites

The following allows for the addition of the category name to the list of downloadable products in the Customer's Account's Downloads page. (The email edits follow.)

 

In the file cubecart.class.php, near line 1756 in the private function _download(), find:

                foreach ($downloads as $download) {
                    if (($product = $GLOBALS['db']->select('CubeCart_order_inventory', false, array('id' => $download['order_inv_id']))) !== false) {
                        $download['expires'] = ($download['expire'] > 0) ? formatTime($download['expire']) : $GLOBALS['language']->common['never'];

Between the second and third line above, add the following:

if($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id'])) !== false) {
$download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;
}

In the skin template file content.downloads.php, find:

<a href="{$download.product_url}" title="{$LANG.catalogue.view_product}">{$download.name}</a>

Add the desired HTML that places the category name for the product where needed. Use this variable to show it: {$download.cat_name}

 

 

For the email:

 

In the file order.class.php, near line 609 in the private function _digitalDelivery(), find:

                foreach ($digital as $offset => $download) {
                    // Get product name
                    $product = $GLOBALS['db']->select('CubeCart_order_inventory', array('name'), array('id' => $download['order_inv_id']));
                    // Set minimum expiry time (min 30 mins = 1800 seconds)

Between the third and fourth line above, add the following:

if($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id'])) !== false) {
$download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;
}

Find: $dkeys[] = array(

On a new blank line after that, add:

'cat_name' => $download['cat_name'],

 

Now there are two important changes to the code nearby:

Two lines after: private function _digitalDelivery($order_id, $email)

Find and change this part: array('digital_id', 'accesskey', 'order_inv_id'),

To be this: false,

 

Three lines later, find and change this part: array('name'),

To be this: false,

 

In admin, Email Templates, click the flag of the language you want to edit for Cart: Digital Download. On the HTML Content and Plain Text Content tabs, you now have {$download.cat_name} available.

Link to comment
Share on other sites

Check please...

 

#1 cubecart.class.php 

 

 

foreach ($downloads as $download) {

                    if (($product = $GLOBALS['db']->select('CubeCart_order_inventory', false, array('id' => $download['order_inv_id']))) !== false) {
                        
                     if($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id'])) !== false) {
$download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;
}
                      $download['expires'] = ($download['expire'] > 0) ? formatTime($download['expire']) : $GLOBALS['language']->common['never'];

 

 

#3 order.class.php

 

 

foreach ($digital as $offset => $download) {
                    // Get product name
                    $product = $GLOBALS['db']->select('CubeCart_order_inventory', array('name'), array('id' => $download['order_inv_id']));
                    
                    if($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id'])) !== false) { 
                    $download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;}
                    
                    // Set minimum expiry time (min 30 mins = 1800 seconds)

 

#4 order.class.php

 

 

private function _digitalDelivery($order_id, $email) {

if (!empty($order_id) && !empty($email)) {
if (($digital = $GLOBALS['db']->select('CubeCart_downloads', false, array('cart_order_id' => $order_id))) !== false) {
foreach ($digital as $offset => $download) {
// Get product name
$product = $GLOBALS['db']->select('CubeCart_order_inventory', false, array('id' => $download['order_inv_id']));
// Set minimum expiry time (min 30 mins = 1800 seconds)
$validity_time = ($GLOBALS['config']->get('config', 'download_expire') > 1800) ? $GLOBALS['config']->get('config', 'download_expire') : 1800;
$expire = time() + $validity_time;
$GLOBALS['db']->update('CubeCart_downloads', array('expire' => $expire), array('digital_id' => $download['digital_id']));
$dkeys[] = array(
'cat_name' => $download['cat_name'],
'accesskey' => $download['accesskey'],
'name' => $product[0]['name'],
'expire' => formatTime($expire, false, true),
);
}

 

(I did not include the skin template content.download.php.)

 

I am testing the email next. Let me know how this looks to you. I was a bit thrown by setting the array() to false, did I do that correctly?

Link to comment
Share on other sites

bsmithers you have been a fantastic help on this project. I don't want to use up my good will by asking too much, so please let me know. 

 

Two questions:

1 - It says "Not Applicable" in the space where the category name should be. I see the code, but am not sure what it should be. 

 

 

 

 

Your digital files are now ready for download. Please use the links provided below to access them below:

 

Not Applicable

Annual budget report or summary, including reserve study Sections 5300 and 4525(a)(3): (Link expires on 30 Jan 2014, 16:49)


http://tmadocuments.com/index.php?_a=download&accesskey=6a0e1134d3cf0546aba3b71eecb11c6a

 

2 - Does this code make the $product.cat_name available to all the email templates?
The documents are part of a legal package that my client provides and the cat_name is an owners association that is tied to the documents. The name should accompany the other email confirmations and receipts. 

 

Thank you for your consideration on this. 

M

Link to comment
Share on other sites

In post#13, you quoted changes you made to order.class.php.

 

In quote#3, I see the two lines you were to add, but in quote#4, they are not there.

 

Please re-examine the edits you made to the private function _digitalDelivery($order_id, $email).

 

This specific change makes {$download.cat_name} available for the Digital Download email. None of the above edits makes the cat_name available to any other email template. But we can try something else to make it so.

Link to comment
Share on other sites

As per the comments on post #15, here is the code that is in place on the order.class.php. Highlights are the changed code. 

 

 

private function _digitalDelivery($order_id, $email) {

if (!empty($order_id) && !empty($email)) {
if (($digital = $GLOBALS['db']->select('CubeCart_downloads', false, array('cart_order_id' => $order_id))) !== false) {
foreach ($digital as $offset => $download) {
// Get product name
$product = $GLOBALS['db']->select('CubeCart_order_inventory', false, array('id' => $download['order_inv_id']));
 
if($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id'])) !== false) {
$download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;}
 
// Set minimum expiry time (min 30 mins = 1800 seconds)
$validity_time = ($GLOBALS['config']->get('config', 'download_expire') > 1800) ? $GLOBALS['config']->get('config', 'download_expire') : 1800;
$expire = time() + $validity_time;
$GLOBALS['db']->update('CubeCart_downloads', array('expire' => $expire), array('digital_id' => $download['digital_id']));
$dkeys[] = array(
'cat_name' => $download['cat_name'],
'accesskey' => $download['accesskey'],
'name' => $product[0]['name'],
'expire' => formatTime($expire, false, true),
);
}

 

Am I doing this correctly? The email does not contain the cat_name. Thanks for your consideration. 

M

Link to comment
Share on other sites

In _digitalDelivery(), find:

                    foreach ($dkeys as $dkey) {
                        $download['url']     = $storeURL.'/index.php?_a=download&accesskey='.$dkey['accesskey'];
                        $download['name']     = $dkey['name'];
                        $download['expire'] = $dkey['expire'];
                        $downloads[] = $download;
                    }
                    $GLOBALS['smarty']->assign('DOWNLOADS',$downloads);

Between the first and second lines above, add:

                        $download['cat_name'] = $dkey['cat_name'];
Link to comment
Share on other sites

  • 2 months later...

It has been a while, but I have to revisit this issue.

 

I have double checked all of the above code changes, but the cat_name option is still not available for use on the digital downloads email. 

Should it be available in the options listed below the email editing box? I have tried to simply add it to the source code of the email, but it still comes back as "Not Applicable". 

 

If you get a chance, could we look at it one more time? 

Link to comment
Share on other sites

Seeing "Not Applicable" means all the code changes are working properly.

 

The statement:

$download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;}

is where 'Not Applicable' is coming from. It is the 'false' result of this test:

$GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])

which means the function is returning false.

 

The function returns false when there is no category with that cat_id, the category with that cat_id is not enabled, or the argument to the function is bad.

 

But first, let's break apart this statement to individual pieces, just in case the statement is not agreeable to PHP:

Was:
$download['cat_name'] = ($prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id'])) ? $prod_cat_name['cat_name'] : "Not Applicable" ;}
Now:
$prod_cat_name = $GLOBALS['catalogue']->getCategoryData($download_product_data[0]['cat_id']);
$download['cat_name'] = (!empty($prod_cat_name)) ? $prod_cat_name['cat_name'] : "Not Applicable" ;}

Do you have access to the PHP error log? If so, we can intentionally send some entries to the log with the values of these variables to see what is actually happening.

Link to comment
Share on other sites

  • 2 weeks later...

A silly typo in order.class.php:

Was:
if($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id'])) !== false) {
 
Now:
if( ($download_product_data = $GLOBALS['db']->select('CubeCart_inventory', 'cat_id', array('product_id' => $download['product_id']))) !== false ) {
Link to comment
Share on other sites

Question: The option to use {$download.cat_name} in the Customer Digital Download email is not listed as one of the useable variables. In the list at the bottom of the email template, I see the usual set variable, but {$download.cat_name} is not there. 

 

Should it be there for me to use it? 

Link to comment
Share on other sites

{$download.cat_name} is available, but won't be listed in the table.

 

The table of useable variable names is 'static', that is, the code has unchanging information set up in an array. There is an unfinished "hook" statement at the bottom of this array for a plug-in author to have any new items added to the array via that plug-in.

 

But since this particular hack is all edits to existing code, and not a plug-in, you must take note in the discussion above as to what has just become available.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...