Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2007
    Posts
    5
    Plugin Contributions
    0

    Default Custom product_type and products_options_types in tpl_shopping_cart_default.php

    I'm creating a new product type that allows customers to change the look of the product they are buying. For example, they buy a t-shirt and can change the text on the shirt along with the shirt color which results in the product image and thumbnail being updated to reflect their choices.

    I'm approaching this by creating a new product type called "product_customizable" and have followed the path outlined in http://www.zen-cart.com/wiki/index.php/Product_Types

    I've also added a new products_options_type called "Hidden" based off of the "Text" type. This lets me add attributes (such as X & Y coordinates for lettering) that the customer shouldn't see as part of their order but is needed on the back-end.

    So my questions to all the experienced zencarters out there:

    1) During checkout, I would like to hide the product attributes that are of my new products_options_type "Hidden". I think I need to modify header_php.php so that the product_option_type floats up and can be accessed. Suggestions on how to do this or a better approach? I'm having a tough time understanding all the code in that file.

    2) I can detect if a product in the shopping cart corresponds to my new product_type by using
    PHP Code:
    if (zen_get_info_page($product['id']) == 'product_customizable_info') {...} 
    , but what is the syntax for pulling individual product attribute values out in the product page and the shopping cart? For example, I need to use the text value in one of my Hidden products_options_types as the filename for the custom image to display in the shopping cart.

    Thanks!

  2. #2
    Join Date
    Oct 2007
    Posts
    5
    Plugin Contributions
    0

    Default [Solution] Re: Custom product_type and products_options_types...

    Ok, I think I've got it - or at least it works now. I'm posting my solution in the hope it will help someone in the future. Feedback on my approach are appreciated. Thanks,
    -)----- B

    In header_php.php I modified the query by adding the product_options_type:
    PHP Code:
          $attributes "SELECT popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, popt.products_options_type
                         FROM " 
    TABLE_PRODUCTS_OPTIONS " popt, " TABLE_PRODUCTS_OPTIONS_VALUES " poval, " TABLE_PRODUCTS_ATTRIBUTES " pa
                         WHERE pa.products_id = :productsID
                         AND pa.options_id = :optionsID
                         AND pa.options_id = popt.products_options_id
                         AND pa.options_values_id = :optionsValuesID
                         AND pa.options_values_id = poval.products_options_values_id
                         AND popt.language_id = :languageID
                         AND poval.language_id = :languageID " 
    $options_order_by
    Then after this line:
    PHP Code:
          $attrArray[$option]['price_prefix'] = $attributes_values->fields['price_prefix']; 
    I added the following:
    PHP Code:
          $attrArray[$option]['products_options_type'] = $attributes_values->fields['products_options_type'];
          if (
    $attrArray[$option]['products_options_name'] == 'CustomImageID') {
            
    $productsCustomImageID zen_output_string_protected($attr_value);
          } 
    The first line exposes the product_options_type to be read from the tpl_shopping_cart_default.php page. The if block detects which option contains the value I need to use in displaying the customized product image in the shopping cart.

    I then added 'productsCustomImageID'=>$productsCustomImageID, to the list of values that get stored as an array into $productArray[$i]
    PHP Code:
     $productArray[$i] = array('attributeHiddenField'=>$attributeHiddenField,
                                
    'flagStockCheck'=>$flagStockCheck,
                                
    'flagShowFixedQuantity'=>$showFixedQuantity,
                                
    'linkProductsImage'=>$linkProductsImage,
                                
    'linkProductsName'=>$linkProductsName,
                                
    'productsImage'=>$productsImage,
                                
    'productsName'=>$productsName,
                                
    'showFixedQuantity'=>$showFixedQuantity,
                                
    'showFixedQuantityAmount'=>$showFixedQuantityAmount,
                                
    'showMinUnits'=>$showMinUnits,
                                
    'quantityField'=>$quantityField,
                                
    'buttonUpdate'=>$buttonUpdate,
                                
    'productsPrice'=>$productsPrice,
                                
    'productsPriceEach'=>$productsPriceEach,
                                
    'rowClass'=>$rowClass,
                                
    'buttonDelete'=>$buttonDelete,
                                
    'checkBoxDelete'=>$checkBoxDelete,
                                
    'id'=>$products[$i]['id'],
                                
    'productsCustomImageID'=>$productsCustomImageID,
                                
    'attributes'=>$attrArray); 
    After I made the above changes, I made the following changes to tbl_shopping_cart_default.php. First I check to see if this product is one of my new customizable products and if it is, I will retrieve the CustomImageID and display the img otherwise I'll let zencart display its own product image:
    PHP Code:
        if  (zen_get_info_page($product['id']) == 'product_customizable_info') {
          echo 
    '<img src="'.$product['productsCustomImageID'].'.jpg" />';
        } else {
          echo 
    $product['productsImage'];
        } 
    And then I modified the foreach loop that displays the attribute options to ignore my attributes that should be hidden
    PHP Code:
    <?php
      
    echo $product['attributeHiddenField'];
      if (isset(
    $product['attributes']) && is_array($product['attributes'])) {
        echo 
    '<div class="cartAttribsList">';
        echo 
    '<ul>';
        
    reset($product['attributes']);
        foreach (
    $product['attributes'] as $option => $value) {
    ?>

    <?php 
          
    if ($value['products_options_type'] == PRODUCTS_OPTIONS_TYPE_HIDDEN) {
            echo 
    "\n".'<!-- '.$value['products_options_name'] . ' ' nl2br($value['products_options_values_name']).' -->'."\n"
          } else {
            echo 
    '<li>'.$value['products_options_name'] . TEXT_OPTION_DIVIDER nl2br($value['products_options_values_name']).'</li>'
          }
        
    ?></li>

    <?php
        
    }
        echo 
    '</ul>';
        echo 
    '</div>';
      }
    ?>
    Note: PRODUCTS_OPTIONS_TYPE_HIDDEN was defined in the product_options_types and configuration tables.

 

 

Similar Threads

  1. where tpl_shopping_cart_default.php called
    By alvalong in forum Contribution-Writing Guidelines
    Replies: 2
    Last Post: 4 Nov 2008, 05:42 AM
  2. fatal error - tpl_shopping_cart_default.php
    By tchambro in forum General Questions
    Replies: 1
    Last Post: 1 Apr 2007, 10:07 PM
  3. Replies: 1
    Last Post: 22 Jan 2007, 09:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg