SOLVED
My problem is solved for displaying additional hints and enable/disable the "Add to cart" button. I would like to post here, what it did to solve that problem, so that maybe other users can use a solution like mine.
Since I had to manipulate the product detail page of some products in my store, I added custom fields via the Hika-Shop Administration UI to the products table. In my case, there are some boolean values called:
product_requires_wes
product_requires_contract
product_requires_criminal_record_doc
product_requires_adult
product_restrict_online_sale
For business reasons, I had to add two additional fields to the users table called:
user_date_of_birth
user_validity_expire_date
(both are of type "date")
I wanted two things:
a.) to display a hint message text on the product page, depending on the flags above
b.) display/hide the "Add to cart button" based on the flags above
I did 2 tings:
1.) I wrote a little php code file to cover a.)
public_html/shop/components/com_hikashop/views/product/tmpl/show_block_product_gunshop_notices.php
2.) I added a call to this code to the show_default.php file (at the very end of the file)
<?php
$this->setLayout('show_block_product_gunshop_notices');
echo $this->loadTemplate();
?>
3.) To cover the business cases for b.) I changed the logic of the quantity.php file. I just added this code in the block where the file starts after:
defined('_JEXEC') or die('Restricted access');
?>
<?php
// Read product values from current record
$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;
// Load user data and read them to the required variables
$hikaShopUser = hikaShop_loadUser(true);
$isUserLoggedIn = (is_null($hikaShopUser)) ? false : true;
$userAge = 0;
$isUserAdult = false;
$isUsersPermitValid = false;
$isUsersBirthdateRegistered = false;
$isUsersValidityExpireDateRegistered = false;
if ($isUserLoggedIn) {
// Calculate age of customer
$usersBirthdate = $hikaShopUser->user_date_of_birth;
if(!is_null($usersBirthdate)) {
if(strlen($usersBirthdate) > 0) {
$isUsersBirthdateRegistered = true;
$birthday_timestamp = strtotime($hikaShopUser->user_date_of_birth);
$userAge = date('md', $birthday_timestamp) > date('md') ? date('Y') - date('Y', $birthday_timestamp) - 1 : date('Y') - date('Y', $birthday_timestamp);
if($userAge < 0) {
$userAge = 0; // in case when a future date has been entered for birthdate.
}
if($userAge >= 18) {
$isUserAdult = true;
}
}
}
// Calculate if the user is valid.
$usersValidityExpireDate = $hikaShopUser->user_validity_expire_date;
if(!is_null($usersValidityExpireDate)) {
if(strlen($usersValidityExpireDate) > 0) {
$isUsersValidityExpireDateRegistered = true;
$validity_timestamp = strtotime($hikaShopUser->user_validity_expire_date);
$now_timestamp = strtotime("now");
if($validity_timestamp > $now_timestamp) {
$isUsersPermitValid = true;
}
else {
if($validity_timestamp == $now_timestamp) {
$isUsersPermitValid = true;
}
}
}
}
}
$displayCart = true;
if($productIsWesRequired || $productIsContractRequired || $productIsRestrictedForOnlineSale)
{
$displayCart = false;
}
else if ($productIsCriminalRecordRequired && $isUsersPermitValid == false)
{
$displayCart = false;
}
else if($productIsAdultRequired && $isUserAdult == false)
{
$displayCart = false;
}
$displayNoStockMessage = true;
if($productIsWesRequired || $productIsContractRequired || $productIsRestrictedForOnlineSale)
{
$displayNoStockMessage = false;
}
if($productIsWesRequired || $productIsContractRequired || $productIsCriminalRecordRequired || $productIsAdultRequired || $productIsRestrictedForOnlineSale) {?>
<br /><p><a href="#anch_important_product_notice"><strong><span style="background-color: #ffff00; color: #ff0000;"><?php echo JText::_('CHECK_SPECIAL_PRODUCT_NOTICE_ENDOFPAGE') ?></span></strong></a></p><br />
<?php }
I had to change the line:
}elseif(!$this->params->get('catalogue') && ($this->config->get('display_add_to_cart_for_free_products') || !empty($this->row->prices))){
to this...
}elseif(!$this->params->get('catalogue') && $displayCart && ($this->config->get('display_add_to_cart_for_free_products') || !empty($this->row->prices))){
4.) I also changed the line where the no-stock information is shown:
if($displayNoStockMessage)
{
echo JText::_('NO_STOCK');
}
And here you can find, what I did: Please keep in mind, that I'm not a professional PHP-Programmer, so therefore my code must look terrible, but it seems that it works so far pretty well. I couldn't manage to make functions and include files and stuff like that and therefore the code is just "monolitic and as a block". Sorry for that, but I was not able to find the problem (locally in my NetBeans/XAMPP environment, includes worked well, but on my webserver it failed and I couldn't find the reason).
Maybe there are some suggestions for my code: I'm always open for good ideas.
Thank you and hopefully, this can help other people with their shop.
Regards, Mike
@Hika-Team and this forum: THANKS FOR THE HELP AND KEEP UP THE GOOD WORK!