News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Cart variant custom field in VM catalogue mode. Bug?

Started by MarioP, December 14, 2013, 11:23:14 AM

Previous topic - Next topic

MarioP

Hello.
I use VM as a product catalogue only. Nonetheless I use prices and I would like to apply the Cart variant custom field to include a selector that allows the customer to choose the preferred additional equipment and display the amended price. Everything works beside the automated price changing...When I choose one of the options the product price still remains the same.  Is there any option to change that? Is it possible in the catalogue mode? If we (VM catalog mode users :) ) have oportunity to use that great thing which is cart variant custom field why we don't have opportunity to use it fully?


[attachment cleanup by admin]

Peter Pillen

in virtuemart > configuration > configuration > tab templates

in the box below on the right "css and javascripts"

is the article scripts activated? Normally that script handles the price displays (and changes)

MarioP

Quoteis the article scripts activated?
Yes, they are.
The feature works, but only if I disable the 'Use only as catalogue' in BE configuration (I use standard cart functions).  But of course I don't want to use VM as a shop, but only as a catalogue. With that setting automated price changing doesn't work...

Peter Pillen

Then your best option is to disable the "use as catalogue only" and remove the order button from your template by commenting out the code.

MarioP

Thank you for trying to help but even if it will work...When I will use the standard VM cart mode and only comment out the order button, if it won't cause other problems with the site activity as a catalogue? I counted rather on a solution in the standard VM release (of course if the issue I described will consider as a bug or although as useful feature). If not, maybe someone could help me by giving some more specific clues what do to (I'm beginning at VM and programming).

Peter Pillen

Lets suppose you are using a template override. The file for the productdetailsview is then located in templates\*your template*\html\com_virtuemart\productdetails\default.php

If you search the file for if (!VmConfig::get('use_as_catalog',0)) {, you will normally see a form with 3 items being located within that if-loop

customfieldscart, customschilds and the add to cart button. Like below

if (!VmConfig::get('use_as_catalog',0)) {
   customfieldscart div
   customschilds div
   add to cart button div
}

If you adapt your template so that the div's that handle the prices are not located inside the use as catalogue check, they will show up as you whish them to. In that case the if- loop only contains the button. Just add an extra loop arround the button and remove the first loop check.

if (!VmConfig::get('use_as_catalog',0)) {
      customfieldscart div
      customschilds div
  if (!VmConfig::get('use_as_catalog',0)) {
      add to cart button div
   }
}

This is not a core hack, but a template setting. There is no need for the developpers to add another functionality in this case.

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

MarioP

in /public_html/templates/my_template/html/com_virtuemart/productdetails default.php I have follwing code
<?php
// Add To Cart Button
//  if (!empty($this->product->prices) and !empty($this->product->images[0]) and $this->product->images[0]->file_is_downloadable==0 ) {
// if (!VmConfig::get('use_as_catalog', 0) and !empty($this->product->prices['salesPrice'])) {
    echo $this->loadTemplate('addtocart');
// }  // Add To Cart Button END
?>

How to implement your advice to aforementioned code? Maybe the soultion is in 'addtocart' file, becuase when I commented out the line, the cart variant custom field and the cart button are gone...

Peter Pillen

You will have to look further in the addtocart template that is loaded. Remember that all template overrides are different, so most people don't have the same template files. That's why I've written a global description code to help you on the way. Maybe post the addtocart template code here so we can have a look.

MarioP

I copied the template from /public_html/components/com_virtuemart/views/productdetails/tmpl so it's the default VM product details template, right?
Below is the code of default_addtocart.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);
?>

<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 JText::($field->custom_title?></strong></span>
<?php }
if ($field->custom_tip) {
echo JHTML::tooltip ($field->custom_tipJText::($field->custom_title), 'tooltip.png');
?>
</span>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo $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>
<input type="hidden" class="pname" value="<?php echo htmlentities($this->product->product_nameENT_QUOTES'utf-8'?>"/>
<input type="hidden" name="view" value="cart"/>
<noscript><input type="hidden" name="task" value="add"/></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>"/>
<?php
}
?>

<?php
}
?>

<div class="clear"></div>
</div>
<?php
}
?>

<input type="hidden" name="option" value="com_virtuemart"/>

</form>
<div class="clear"></div>
</div>

Peter Pillen

I modified the file to how it should normally work for you.

I commented out the if (!VmConfig::get('use_as_catalog', 0)  ) { on line 54, together with the bracket on line 120 that goes with it.
and then placed the same if-clause arround the add to cart button on line 100 with a bracket on line 111

Together with the change you made in /public_html/templates/my_template/html/com_virtuemart/productdetails default.php, you should normally get the price functionality without the button.

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);
?>

<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 JText::($field->custom_title?></strong></span>
<?php }
if ($field->custom_tip) {
echo JHTML::tooltip ($field->custom_tipJText::($field->custom_title), 'tooltip.png');
?>
</span>
<span class="product-field-display"><?php echo $field->display ?></span>
<span class="product-field-desc"><?php echo $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
if (!VmConfig::get('use_as_catalog'0)  ) {
// 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>
<input type="hidden" class="pname" value="<?php echo htmlentities($this->product->product_nameENT_QUOTES'utf-8'?>"/>
<input type="hidden" name="view" value="cart"/>
<noscript><input type="hidden" name="task" value="add"/></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>"/>
<?php
}
}
?>

<?php
}
?>

<div class="clear"></div>
</div>
<?php
//}
?>

<input type="hidden" name="option" value="com_virtuemart"/>

</form>
<div class="clear"></div>
</div>

MarioP

Tested, unfortunately doesn't work. The add to cart button was removed (apart from the quantity box) but the automated price changing still does not operate.

MarioP

Because there is no option to solve the problem without VM core hacking (unless there is some way to do that, but unfortunately I have no idea how) Do you (VM developers) consider aforementioned issue as a bug? Can I (We) count on any bugfix action? If not , just please to inform ( I've asked about that already, but unfortunately I haven't got any answer so far...)

Milbo

Will be addressed in vm2.2. Take care for that, I cannot promise that I remind to test it and to make it working, but vm2.2 has an architectural change to make this easier. So just join our testing team, when we released the first downloadable version vm2.1
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/