Access to Products and "Characteristics"

  • Posts: 108
  • Thank you received: 4
  • Hikashop Business
12 years 2 months ago #64728

Hello there

I would like to ask a question about products and products that are specified over characteristics. I specified some custom fields on the product. Now, I use the default-hikashop view to display my products.

I want do adapt the show_default - View to display some custom information based on the custom fields on the product. Some products has "Characteristics" like "Color" or "Edition" and different custom fields value.

How can I access in the show_default View the displayed product (maybe a product based on "Characteristics")? How can I determine, if a product based on Characteristics is displayed (because a customer selected a variation of the product)? And how Do i access them. I cannot find out.

Thank your for your help and best regards
Mike

Please Log in or Create an account to join the conversation.

  • Posts: 82818
  • Thank you received: 13362
  • MODERATOR
12 years 2 months ago #64777

The display product information is available with $this->element

You can check if the product has variants like that:
if(empty($this->element->variants)){
//no variants
}else{
//with variants
}

If you do a var_dump of $this->element you will be able to see ALL the data of the product.

The following user(s) said Thank You: mike

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 4
  • Hikashop Business
12 years 2 months ago #64779

cool thanks, I'll try it out!

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 4
  • Hikashop Business
12 years 2 months ago #65024

Hmmm, I think I'm to stupid for that.

If you check out the following product page:

www.waffenmarti.ch/shop/our-products/pro...tole-mark-xix-2.html

I have some different types of this product. For example has the "Titanium Gold" Model other custom attributes than the "Titanium Gold with Tigerstribes". At the bottom of the page you can see a yellow box that says "Wichtige Produktehinweise". This "Wichtige Produktehinweise" should differ.

I added in the show_default.php the following code that should make the difference:

<?php
$productIsWesRequired = false;
$productIsContractRequired = false;
$productIsCriminalRecordRequired = false;
$productIsAdultRequired = false;
$productIsRestrictedForOnlineSale = false;

if(isset($this->element->main))
{
  echo 'MAIN';
  $productIsWesRequired = (strcasecmp($this->element->main->product_requires_wes, "yeswes") == 0) ? true : false;
  $productIsContractRequired = (strcasecmp($this->element->main->product_requires_contract, "yescontract") == 0) ? true : false;
  $productIsCriminalRecordRequired = (strcasecmp($this->element->main->product_requires_criminal_record_doc, "yescriminalrecord") == 0) ? true : false;
  $productIsAdultRequired = (strcasecmp($this->element->main->product_requires_adult, "yesadult") == 0) ? true : false;
  $productIsRestrictedForOnlineSale = (strcasecmp($this->element->main->product_restrict_online_sale, "yesrestrictedonlinesale") == 0) ? true : false;
}
else{
  echo 'VARIANT';
  $productIsWesRequired = (strcasecmp($this->element->product_requires_wes, "yeswes") == 0) ? true : false;
  $productIsContractRequired = (strcasecmp($this->element->product_requires_contract, "yescontract") == 0) ? true : false;
  $productIsCriminalRecordRequired = (strcasecmp($this->element->product_requires_criminal_record_doc, "yescriminalrecord") == 0) ? true : false;
  $productIsAdultRequired = (strcasecmp($this->element->product_requires_adult, "yesadult") == 0) ? true : false;
  $productIsRestrictedForOnlineSale = (strcasecmp($this->element->product_restrict_online_sale, "yesrestrictedonlinesale") == 0) ? true : false;
}
?>

<?php if ($productIsWesRequired || $productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired || $productIsRestrictedForOnlineSale) { ?>
    <div id="hikashop_product_custom_info_main" class="hikashop_product_custom_info_main">
        <table style="border-color: #ff0000; border-width: 2px; border-style: solid;" border="2" cellpadding="10">
            <tbody>
                <tr>
                    <td style="border-style: solid; border-width: 1px; background-color: #ffff00;">
                        <h2><strong><span style="color: #000000;"><a name="anch_important_product_notice"></a><?php echo JText::_('PRODUCT_ADDITIONAL_INFORMATION_TITLE') ?></span></strong></h2>
                        <?php if( ($productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired) && !$productIsRestrictedForOnlineSale) { ?>
                            <p><strong><span style="color: #000000;"><a href="anmelden-abmelden.html"><?php echo JText::_('PRODUCT_LOGIN_TO_SHOP') ?></a><?php echo JText::_('PRODUCT_SOLD_ONLY_TO_VERIFIED_CUSTOMERS') ?><br /></span></strong></p>
                        <?php } ?>
                        <ul>
                            <?php if($productIsRestrictedForOnlineSale) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_RESTRICTED_FOR_ONLINE_SALE') ?></span></strong></li>
                            <?php } ?>
                            <?php if($productIsAdultRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_SOLD_ONLY_TO_ADULTS') ?><br /></span></strong></li>
                            <?php } ?>
                            <?php if($productIsContractRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_A_CONTRACT') ?><br /></span></strong></li>
                            <?php } ?>
                            <?php if($productIsWesRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_WES') ?><br /></span></strong></li>
                            <?php } ?>
                            <?php if($productIsCriminalRecordRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_CRIMINAL_RECORD') ?><br /></span></strong></li>
                            <?php } ?>
                        </ul>
                        <?php if($productIsCriminalRecordRequired || $productIsAdultRequired || $productIsWesRequired) { ?>    
                            <p><strong><span style="color: #000000;"><a href="kontakt.html"><?php echo JText::_('PRODUCT_GET_IN_TOUCH_WITH_US') ?></a><?php echo JText::_('PRODUCT_WE_NEED_PAPERS_FROM_YOU') ?><br /></span></strong></p>
                        <?php } ?>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
<?php
}?>

What I want todo is in case the customer selects another "Desert Eagle Ausführungen" (Model) the yellow box with the hints shall display the custom attributes from the variant and not from the main-product. It's really difficult to explain. I hope you can understand what I want?

I found out, that somehow, the shop.php is involved since I had to add there some code I also added in the "show_block_custom_main.php". This code do not print specifications of my internal used product tags (like product_requires_wes, product_requires_contract, product_requires_criminal_record_doc, product_requires_adult, product_restrict_online_sale).

I hope you can help me out :(
Thanks for your help!

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 4
  • Hikashop Business
12 years 2 months ago #65053

Ah okay, I found something out... shop.php creates a "section" for every variant of the product. If the variant is selected in the dropdown box, the appropriate information are displayed. So far so good, but if you just come to the product page the first time, the default selection of the variant is considered only if you change the selection to another variant and then back to the default variant.

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 4
  • Hikashop Business
12 years 2 months ago #65057

Okay, it seems I found the solution. I will post it later when I'm sure, that it's okay for me!

Please Log in or Create an account to join the conversation.

  • Posts: 108
  • Thank you received: 4
  • Hikashop Business
12 years 2 months ago #65086

I found it: It seems to be necessary to add the code to show_default.php and show.php. I've added now my additional information (see the code above), in the following section:

show_default.php

<div id="hikashop_product_description_main" class="hikashop_product_description_main">
    <?php
      if( strcasecmp($this->element->product_other_models_available_hint, "yesOtherModelsHint") == 0 ) {
        if (!empty ($this->element->product_url)) { ?>
          <p style="text-align: center;"><span style="text-decoration: underline;"><a href="<?php echo $this->element->product_url ?>"><span style="color: #ff0000;"><strong><?php echo JText::_('OTHER_MODELS_AVAILABLE_HINT') ?></strong></span></a></span></p>
        <?php
        }
        else { ?>
          <p style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #ff0000;"><strong><?php echo JText::_('OTHER_MODELS_AVAILABLE_HINT') ?></strong></span></a></span></p>
        <?php
        }
    }
    ?>

    <?php
    echo JHTML::_('content.prepare',preg_replace('#<hr *id="system-readmore" */>#i','',$this->element->product_description));
    echo '</br>';
    echo '</br>';
    ?>
    
    <?php
    $productIsWesRequired = (strcasecmp($this->element->product_requires_wes, "yeswes") == 0) ? true : false;
    $productIsContractRequired = (strcasecmp($this->element->product_requires_contract, "yescontract") == 0) ? true : false;
    $productIsCriminalRecordRequired = (strcasecmp($this->element->product_requires_criminal_record_doc, "yescriminalrecord") == 0) ? true : false;
    $productIsAdultRequired = (strcasecmp($this->element->product_requires_adult, "yesadult") == 0) ? true : false;
    $productIsRestrictedForOnlineSale = (strcasecmp($this->element->product_restrict_online_sale, "yesrestrictedonlinesale") == 0) ? true : false;
    ?>

    <?php if ($productIsWesRequired || $productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired || $productIsRestrictedForOnlineSale) { ?>
        <h2><strong><span style="color: #000000;"><a name="anch_important_product_notice"></a><?php echo JText::_('PRODUCT_ADDITIONAL_INFORMATION_TITLE') ?></span></strong></h2>
        <table style="border-color: #ff0000; border-width: 2px; border-style: solid;" border="2" cellpadding="10">
            <tbody>
                <tr>
                    <td style="border-style: solid; border-width: 1px; background-color: #ffff00;">
                        
                        <?php if( ($productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired) && !$productIsRestrictedForOnlineSale) { ?>
                            <p><strong><span style="color: #000000;"><a href="anmelden-abmelden.html"><?php echo JText::_('PRODUCT_LOGIN_TO_SHOP') ?></a><?php echo JText::_('PRODUCT_SOLD_ONLY_TO_VERIFIED_CUSTOMERS') ?><br /></span></strong></p>
                        <?php } ?>
                        <ul>
                            <?php if($productIsRestrictedForOnlineSale) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_RESTRICTED_FOR_ONLINE_SALE') ?></span></strong></li>
                            <?php } ?>
                            <?php if($productIsAdultRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_SOLD_ONLY_TO_ADULTS') ?><br /></span></strong></li>
                            <?php } ?>
                            <?php if($productIsContractRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_A_CONTRACT') ?><br /></span></strong></li>
                            <?php } ?>
                            <?php if($productIsWesRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_WES') ?><br /></span></strong></li>
                            <?php } ?>
                            <?php if($productIsCriminalRecordRequired) { ?>
                                <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_CRIMINAL_RECORD') ?><br /></span></strong></li>
                            <?php } ?>
                        </ul>
                        <?php if($productIsCriminalRecordRequired || $productIsAdultRequired || $productIsWesRequired) { ?>    
                            <p><strong><span style="color: #000000;"><a href="kontakt.html"><?php echo JText::_('PRODUCT_GET_IN_TOUCH_WITH_US') ?></a><?php echo JText::_('PRODUCT_WE_NEED_PAPERS_FROM_YOU') ?><br /></span></strong></p>
                        <?php } ?>
                        </br>
                      <p><strong><a href="#">Zurück zum Produkt</a></strong></p>
                    </td>
                </tr>
            </tbody>
        </table>
<?php
}?>
  </div>

show.php
      <div id="hikashop_product_description_<?php echo $variant_name;?>" style="display:none;">
            <?php
      if( strcasecmp($variant->product_other_models_available_hint, "yesOtherModelsHint") == 0 ) {
        if (!empty ($variant->product_url)) { ?>
          <p style="text-align: center;"><span style="text-decoration: underline;"><a href="<?php echo $variant->product_url ?>"><span style="color: #ff0000;"><strong><?php echo JText::_('OTHER_MODELS_AVAILABLE_HINT') ?></strong></span></a></span></p>
        <?php
        }
        else { ?>
          <p style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #ff0000;"><strong><?php echo JText::_('OTHER_MODELS_AVAILABLE_HINT') ?></strong></span></a></span></p>
        <?php
        }
    }
    ?>
        
        <?php echo JHTML::_('content.prepare',preg_replace('#<hr *id="system-readmore" */>#i','',$variant->product_description));?>
        </br>
        </br>
        
        <?php
        $productIsWesRequired = (strcasecmp($variant->product_requires_wes, "yeswes") == 0) ? true : false;
        $productIsContractRequired = (strcasecmp($variant->product_requires_contract, "yescontract") == 0) ? true : false;
        $productIsCriminalRecordRequired = (strcasecmp($variant->product_requires_criminal_record_doc, "yescriminalrecord") == 0) ? true : false;
        $productIsAdultRequired = (strcasecmp($variant->product_requires_adult, "yesadult") == 0) ? true : false;
        $productIsRestrictedForOnlineSale = (strcasecmp($variant->product_restrict_online_sale, "yesrestrictedonlinesale") == 0) ? true : false;
        ?>

        <?php if ($productIsWesRequired || $productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired || $productIsRestrictedForOnlineSale) { ?>
            <h2><strong><span style="color: #000000;"><a name="anch_important_product_notice"></a><?php echo JText::_('PRODUCT_ADDITIONAL_INFORMATION_TITLE') ?></span></strong></h2>
            <table style="border-color: #ff0000; border-width: 2px; border-style: solid;" border="2" cellpadding="10">
                <tbody>
                    <tr>
                        <td style="border-style: solid; border-width: 1px; background-color: #ffff00;">
                            
                            <?php if( ($productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired) && !$productIsRestrictedForOnlineSale) { ?>
                                <p><strong><span style="color: #000000;"><a href="anmelden-abmelden.html"><?php echo JText::_('PRODUCT_LOGIN_TO_SHOP') ?></a><?php echo JText::_('PRODUCT_SOLD_ONLY_TO_VERIFIED_CUSTOMERS') ?><br /></span></strong></p>
                            <?php } ?>
                            <ul>
                                <?php if($productIsRestrictedForOnlineSale) { ?>
                                    <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_RESTRICTED_FOR_ONLINE_SALE') ?></span></strong></li>
                                <?php } ?>
                                <?php if($productIsAdultRequired) { ?>
                                    <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_SOLD_ONLY_TO_ADULTS') ?><br /></span></strong></li>
                                <?php } ?>
                                <?php if($productIsContractRequired) { ?>
                                    <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_A_CONTRACT') ?><br /></span></strong></li>
                                <?php } ?>
                                <?php if($productIsWesRequired) { ?>
                                    <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_WES') ?><br /></span></strong></li>
                                <?php } ?>
                                <?php if($productIsCriminalRecordRequired) { ?>
                                    <li><strong><span style="color: #000000;"><?php echo JText::_('PRODUCT_REQUIRES_CRIMINAL_RECORD') ?><br /></span></strong></li>
                                <?php } ?>
                            </ul>
                            <?php if($productIsCriminalRecordRequired || $productIsAdultRequired || $productIsWesRequired) { ?>    
                                <p><strong><span style="color: #000000;"><a href="kontakt.html"><?php echo JText::_('PRODUCT_GET_IN_TOUCH_WITH_US') ?></a><?php echo JText::_('PRODUCT_WE_NEED_PAPERS_FROM_YOU') ?><br /></span></strong></p>
                            <?php } ?>
                            </br>
                          <p><strong><a href="#">Zurück zum Produkt</a></strong></p>
                        </td>
                    </tr>
                </tbody>
            </table>
    <?php
    }?>
      </div>

... and now it works!
Best regards Mike

The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

Time to create page: 0.068 seconds
Powered by Kunena Forum