Здравствуйте.
Я воспользовался копированием default_addtocart.php в папку шаблона category для того, чтобы иметь функционал добавления в корзину прям в категориях под каждым товаром.
Данный переопределённый default_addtocart.php исправно работает на детальной странице товара, но даёт сбой при копировании его в папку переопределения вывода категории товаров.
Смотрел-смотрел, не высмотрел. Может вы сможете сказать, что в файле ломает вывод категории товаров.
<?php
/**
defined('_JEXEC') or die('Restricted access');
if (isset($this->product->step_order_level))
$step=$this->product->step_order_level;
else
$step=1;
if($step==0)
$step=1;
$alert=JText::sprintf ('COM_VIRTUEMART_WRONG_AMOUNT_ADDED', $step);
//bng347-32 наверно нижеследующую функцию лучше вывести в require_once ...
function TransUrl($str)
{
$tr = array(
"А"=>"a",
"Б"=>"b",
"В"=>"v",
"Г"=>"g",
"Д"=>"d",
"Е"=>"e",
"Ё"=>"e",
"Ж"=>"j",
"З"=>"z",
"И"=>"i",
"Й"=>"y",
"К"=>"k",
"Л"=>"l",
"М"=>"m",
"Н"=>"n",
"О"=>"o",
"П"=>"p",
"Р"=>"r",
"С"=>"s",
"Т"=>"t",
"У"=>"u",
"Ф"=>"f",
"Х"=>"h",
"Ц"=>"ts",
"Ч"=>"ch",
"Ш"=>"sh",
"Щ"=>"sch",
"Ъ"=>"",
"Ы"=>"i",
"Ь"=>"j",
"Э"=>"e",
"Ю"=>"yu",
"Я"=>"ya",
"а"=>"a",
"б"=>"b",
"в"=>"v",
"г"=>"g",
"д"=>"d",
"е"=>"e",
"ё"=>"e",
"ж"=>"j",
"з"=>"z",
"и"=>"i",
"й"=>"y",
"к"=>"k",
"л"=>"l",
"м"=>"m",
"н"=>"n",
"о"=>"o",
"п"=>"p",
"р"=>"r",
"с"=>"s",
"т"=>"t",
"у"=>"u",
"ф"=>"f",
"х"=>"h",
"ц"=>"ts",
"ч"=>"ch",
"ш"=>"sh",
"щ"=>"sch",
"ъ"=>"y",
"ы"=>"i",
"ь"=>"j",
"э"=>"e",
"ю"=>"yu",
"я"=>"ya",
" "=> "_",
"."=> "",
"/"=> "_",
","=>"_",
"-"=>"_",
"("=>"",
")"=>"",
"["=>"",
"]"=>"",
"="=>"_",
"+"=>"_",
"*"=>"",
"?"=>"",
"\""=>"",
"'"=>"",
"&"=>"",
"%"=>"",
"#"=>"",
"@"=>"",
"!"=>"",
";"=>"",
"№"=>"",
"^"=>"",
":"=>"",
"~"=>"",
"\\"=>""
);
return strtr($str,$tr);
}
//bng347-32 end
?>
<div class="addtocart-area">
<form method="post" class="product js-recalculate" action="<?php echo JRoute::_ ('index.php',false); ?>">
<input name="quantity" type="hidden" value="<?php echo $step ?>" />
<?php // Product custom_fields
if (!empty($this->product->customfieldsCart)) {
?>
<div class="product-fields">
<?php foreach ($this->product->customfieldsCart as $field) { ?>
<div class="product-field product-field-type-<?php echo $field->field_type ?>">
<?php if ($field->show_title) { ?>
<span class="product-fields-title-wrapper"><span class="product-fields-title"><strong><?php echo vmText::_ ($field->custom_title)?></strong></span>
<?php }
if ($field->custom_tip) {
echo JHTML::tooltip (vmText::_($field->custom_tip), vmText::_ ($field->custom_title), 'tooltip.png');
} ?></span>
<span class="product-field-display">
<?php /*bng347-11 bng347-28 bng347-32*/
if($field->custom_title=="Тип багета"||$field->custom_title=="Цвет"||$field->custom_title=="Размер"){
$key = key($this->product->customfieldsCart);
$options = $field->options;
//echo TransUrl($field->custom_title);
?>
<select name="<?php echo "customPrice[$key][$field->virtuemart_custom_id]"; ?>" required class="<?php echo TransUrl($field->custom_title);?>_select">
<option disabled selected><?php echo $field->custom_title;?></option>
<?php foreach($options as $option){
echo '<option value="'.$option->virtuemart_customfield_id.'">'.$option->custom_value.'</option>';
}
?>
</select>
<?php }
else { echo $field->display;}
/*bng347-11 bng347-28 bng347-32 end */
?>
</span>
<span class="product-field-desc"><?php echo vmText::_($field->custom_field_desc)?></span>
</div><br/>
<?php } ?>
</div>
<?php
}
/* Product custom Childs
* to display a simple link use $field->virtuemart_product_id as link to child product_id
* custom_value is relation value to child
*/
if (!empty($this->product->customsChilds)) {
?>
<div class="product-fields">
<?php foreach ($this->product->customsChilds as $field) { ?>
<div class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title"><strong><?php echo JText::_ ($field->field->custom_title)?></strong></span>
<span class="product-field-desc"><?php echo JText::_ ($field->field->custom_value)?></span>
<span class="product-field-display"><?php echo $field->display ?></span>
</div><br/>
<?php } ?>
</div>
<?php
}
if (!VmConfig::get('use_as_catalog', 0) ) {
?>
<div class="addtocart-bar">
<script type="text/javascript">
function check(obj) {
// use the modulus operator '%' to see if there is a remainder
remainder=obj.value % <?php echo $step?>;
quantity=obj.value;
if (remainder != 0) {
alert('<?php echo $alert?>!');
obj.value = quantity-remainder;
return false;
}
return true;
}
</script>
<?php // Display the quantity box
$stockhandle = VmConfig::get ('stockhandle', 'none');
if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($this->product->product_in_stock - $this->product->product_ordered) < 1) {
?>
<a href="<?php echo JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $this->product->virtuemart_product_id); ?>" class="notify"><?php echo JText::_ ('COM_VIRTUEMART_CART_NOTIFY')?></a>
<?php
} else {
$tmpPrice = (float) $this->product->prices['costPrice'];
if (!( VmConfig::get('askprice', 0) and empty($tmpPrice) ) ) {
?>
<!-- <label for="quantity<?php echo $this->product->virtuemart_product_id; ?>" class="quantity_box"><?php echo JText::_ ('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
<span class="quantity-box">
<input type="text" class="quantity-input js-recalculate" name="quantity[]" onblur="check(this);"
value="<?php if (isset($this->product->step_order_level) && (int)$this->product->step_order_level > 0) {
echo $this->product->step_order_level;
} else if(!empty($this->product->min_order_level)){
echo $this->product->min_order_level;
}else {
echo '1';
} ?>"/>
</span>
<span class="quantity-controls js-recalculate">
<input type="button" class="quantity-controls quantity-plus" />
<input type="button" class="quantity-controls quantity-minus" />
</span>
<?php // Display the quantity box END
// Display the add to cart button ?>
<span class="addtocart-button">
<?php echo shopFunctionsF::getAddToCartButton ($this->product->orderable);
// Display the add to cart button END ?>
</span>
<noscript><input type="hidden" name="task" value="add"/></noscript>
<?php
}
?>
<?php
}
?>
<div class="clear"></div>
</div>
<?php
}
?>
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="view" value="cart"/>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>"/>
<input type="hidden" class="pname" value="<?php echo htmlentities($this->product->product_name, ENT_QUOTES, 'utf-8')?>"/>
</form>
<div class="clear"></div>
</div>