X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Product options in product list (https://forum.x-cart.com/showthread.php?t=63615)

tomsell 05-14-2012 05:18 AM

Product options in product list
 
Hi, is there a change to add product option (price modifier etc...) to show in products list? For example under {$product.descr}? Thanks for advance!

totaltec 05-14-2012 05:46 AM

Re: Product options in product list
 
I haven't tested this yet, but it should work fine to display the options. Written for 4.4.5, you may need to modify it for your version. I also assumed you would be placing it within a table, you may need to adjust or remove the row and column tags.

PHP Code:

{if $active_modules.Product_Options ne "" and $product.is_product_options eq 'Y'}
      <
tr>
        <
td>
          <
h2>Product Options</h2>
          {foreach 
from=$product_options item=options}
            <
b>{$options.classtext}</b> - 
            {foreach 
from=$options.options item=option name=option_loop}
              {
$option.option_name}{if not $smarty.foreach.option_loop.last},{/if}
            {/foreach}<
br />
          {/foreach}
        </
td>
      </
tr>
    {/if} 


tomsell 05-14-2012 06:12 AM

Re: Product options in product list
 
Thanks a lot for the quick answer! Well, it just displays the titel "Product Options" not the options itself. Do You have a hint, what would be wrong?

totaltec 05-14-2012 06:25 AM

Re: Product options in product list
 
Tom, I just tested it on my test site: http://trainingpen.com/Acer-TravelMate-212T.html it is working just as I expected it to. I would try and look at the variables in webmaster mode, and see if they are set or not.

Product option variables may have different names or arrangement in your version. I am using 4.4.5.

When you fire up webmaster mode, click the button that shows the variables instead of template names. Then check the variable names. Do you have an array named $product_options? Use control-F to search the debug console window.

tomsell 05-14-2012 07:08 AM

Re: Product options in product list
 
In my version there is not possible to show variables instead of template names I guess. But yes, the array named $product options is present

totaltec 05-14-2012 07:20 AM

Re: Product options in product list
 
It is probably possible for you to see the variables, but you need to apply a patch, or set the debug mode in config.php (I think)

Look at this thread: http://forum.x-cart.com/showthread.php?t=44543&highlight=debug

You can also choose to print the entire array with the smarty command:
{$product_options|@print_r}

Then you can see the variables that you need to access, and figure out why the code isn't working. Your version must refer to the options differently. I suspect it might not have the classtext part, maybe it is optiontext or something else in 4.1.11.

SamuraiCoder 05-14-2012 08:01 AM

Re: Product options in product list
 
Hi,

Does anyone have any ideas on how to add product variants to the product list page. I'm having a look at the customer_options.php page but can't seem to find how to make sure its added on the product list page.

xcellere 06-21-2012 10:31 AM

Re: Product options in product list
 
I have the same problem as the OP. When I add the code, the title is all that shows, just no drop down. I did check the variables and $product_options isn't there. How do I load that array?

totaltec 06-21-2012 12:31 PM

Re: Product options in product list
 
Quote:

Originally Posted by xcellere
I have the same problem as the OP. How do I load that array?

After reading back through this thread, I realized that I never understood what the thread was really about. You guys are trying to display the options on the product list, for instance on category pages. I was showing you code that should work on the product page itself. Sorry. Just going too fast, I need to slow down.

You can load the array yourself in php, but you need to determine where the values are pulled from, and access them in the DB. I don't have a quick answer for you unfortunately, I have no idea how product options are handled in 4.1.X

But lets start figuring it out! First lets see how the product options are pulled on the product page. We already have a clue from SamuraiCoder: customer_options.php. Do you have that file in 4.1.X? I think we can assume it is referenced in product.php. So when we pull up the product page, we are really accessing product.php, and then in turn it is including or requiring customer_options.php.

My first step would be to verify that the assumptions I have made above are true, by looking through product.php. Then if so, I would pull open customer_options.php and take a look at how the options were being accessed. Armed with that knowledge we can start determining where we need to add code to pull these options on the page in question.

I believe that the products list is generated by search.php. The actual page we are on when looking at a category is home.php?cat=(somenumber). When ?cat= is included it sets a variable $cat, and the value which is the categoryid. If this is the case it includes search.php (I think) and the database is queried for the products in that category. Our mission is to understand the inner workings of that query, and add the lines that we found in customer_options.php or some variation of those lines. What we are trying to do is pull the product option values for each product found, and assign them to the $products array.

Sorry for the long post, just trying to make sure even a noob could understand. Hopefully that helps.

xcellere 06-21-2012 12:36 PM

Re: Product options in product list
 
Thank you for such a detailed post Mike. I should note that I just updated my signature to show my current version: 4.5. :) No longer 4.1.

EDIT: This is the code in customer_options.tpl:

Code:

{*
$Id: customer_options.tpl,v 1.4.2.1 2010/12/15 09:44:41 aim Exp $
vim: set ts=2 sw=2 sts=2 et:
*}
{if $product_options ne '' or $product_wholesale ne ''}

  {if $nojs ne 'Y'}
    <tr style="display: none;">
      <td colspan="3">

<script type="text/javascript">
//<![CDATA[
var alert_msg = '{$alert_msg|wm_remove|escape:javascript}';
//]]>
</script>
        {include file="modules/Product_Options/check_options.tpl"}
      </td>
    </tr>
  {/if}

  {foreach from=$product_options item=v}
    {if $v.options ne '' or $v.is_modifier eq 'T' or $v.is_modifier eq 'A'}
      <tr>
        <td class="property-name product-input">
          {if $usertype eq "A"}
            {$v.class}
          {else}
            {$v.classtext|escape|default:$v.class}
          {/if}
        </td>
        <td class="property-value" colspan="2">

          {if $cname ne ""}
            {assign var="poname" value="$cname[`$v.classid`]"}
          {else}
            {assign var="poname" value="product_options[`$v.classid`]"}
          {/if}

          {if $v.is_modifier eq 'T'}

            <input id="po{$v.classid}" type="text" name="{$poname}" value="{$v.default|escape}" />

          {elseif $v.is_modifier eq 'A'}

            <textarea id="po{$v.classid}" name="{$poname}">{$v.default|escape}</textarea>

          {else}

            <select id="po{$v.classid}" name="{$poname}"{if $disable} disabled="disabled"{/if}{if $nojs ne 'Y'} onchange="javascript: check_options();"{/if}>

              {foreach from=$v.options item=o}

                <option value="{$o.optionid}"{if $o.selected eq 'Y'} selected="selected"{/if}>
                {strip}
                  {$o.option_name|escape}
                  {if $v.is_modifier eq 'Y' and $o.price_modifier ne 0}
                    &nbsp;(
                    {if $o.modifier_type ne '%'}
                      {currency value=$o.price_modifier display_sign=1 plain_text_message=1}
                    {else}
                      {$o.price_modifier}%
                    {/if}
                    )
                  {/if}
                {/strip}
                </option>

              {/foreach}
            </select>
          {/if}

        </td>
      </tr>
    {/if}

  {/foreach}

{/if}

{if $product_options_ex ne ""}

  <tr>
      <td class="warning-message" colspan="3" id="exception_msg" style="display: none;"></td>
  </tr>

  {if $err ne ''}

    <tr>
      <td colspan="3" class="customer-message">{$lng.txt_product_options_combinations_warn}:</td>
    </tr>

    {foreach from=$product_options_ex item=v}
      <tr>
        <td colspan="3" class="poptions-exceptions-list">

          {foreach from=$v item=o}

            {strip}
            <div>
              {if $usertype eq "A"}
                {$o.class}
              {else}
                {$o.classtext|escape}
              {/if}
              : {$o.option_name|escape}
            </div>
            {/strip}

          {/foreach}

        </td>
      </tr>
    {/foreach}

  {/if}

{/if}



All times are GMT -8. The time now is 03:04 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.