News:

Support the VirtueMart project and become a member

Main Menu

Custom Field with stock control - Add to cart Problem

Started by magelanos, September 01, 2014, 12:24:13 PM

Previous topic - Next topic

magelanos

Hi to everybody.

Although i am not new to virtuemart and joomla, it's my first time posting to this forum.

My question/problem is the following,

I have a shop selling clothes and i wanted to have different stock concerning sizes and color option of the same cloth, let's say "Plaint T-Shirt"
I have created all necessary child products of the same t-shirt with Plain t-Shirt Black Small, Plain t-Shirt Black Medium etc.
I have created a custom field with stock control "Cart Attribute set to yes" and set first option for Colors and Second option for Sizes, I have then added the custom field to the Plain T-Shirt product and it displays absolutely fine.

But! Here is the problem:

Althought it displays fine and you can select the products the quantity box +,- is not working and when you click add to cart it takes you back to the t-shirt general category without adding the product to the cart :( :( :(
Problem:
http://greek4chic.com/men/plaintshirt-detail

This happens only with custom field with stock control! All other products work just fine

Ok Product
http://greek4chic.com/men/tshirts/anarchytshirt-detail

Please advise  :-\

fgozar

Hi magelanos,

if you want ajax popUp
try to add  js-recalculate class at your addtocart form.

This:

<div class="addtocart-area">
<form class="ja-vm-product" action="/men" method="post">

must by

<div class="addtocart-area">
<form class="ja-vm-product js-recalculate" action="/men" method="post">


else try to remove noscript tag from this:

<noscript><input type="hidden" name="task" value="add"/></noscript>

become

<input type="hidden" name="task" value="add"/>




magelanos

fgozar, may i call you friend?

THANKS a THOUSAND!!!!! You saved me. I was trying to figure out why was it doing this and i was hitting a wall! Thanks again!

Just for anybody else who is trying to find a solution to this

I had to do both edits in /templates/ja_hawkstore/html/com_virtuemart/productdetails/default_addtocart.php

This:

<div class="addtocart-area">
<form class="ja-vm-product" action="/men" method="post">

must by

<div class="addtocart-area">
<form class="ja-vm-product js-recalculate" action="/men" method="post">


remove noscript tag from this:

<noscript><input type="hidden" name="task" value="add"/></noscript>

become

<input type="hidden" name="task" value="add"/>

[/quote]

The only thing that is left and is not functioning is the +(plus) and -(minus) sings of the quantity box.

Thanks again for you time!

Quote from: fgozar on September 01, 2014, 19:52:12 PM
Hi magelanos,

if you want ajax popUp
try to add  js-recalculate class at your addtocart form.

This:

<div class="addtocart-area">
<form class="ja-vm-product" action="/men" method="post">

must by

<div class="addtocart-area">
<form class="ja-vm-product js-recalculate" action="/men" method="post">


else try to remove noscript tag from this:

<noscript><input type="hidden" name="task" value="add"/></noscript>

become

<input type="hidden" name="task" value="add"/>


fgozar

Hi magelanos,
as my first reply try to add js-recalculate as class of FORM element.
This must be resolve also minus and plus problem.
All that without  remove noscript element.

You can understand behaviour looking file:
Quote/components/com_virtuemart/assets/js/vmprices.js

I hope that resolve your issue

magelanos

Hi fgozar, i guess i have my mind stuck.....

Here is the code, can you please tell me what to change?

Here is the code

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="ja-vm-product" action="<?php echo JRoute::('index.php'); ?>">
                <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 ?>">
<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) and !empty($this->product->prices['salesPrice'])) {
?>


<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 { ?>
<!-- <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 ?>

<?php
// Display the add to cart button
?>

<span class="addtocart-button">
<?php //echo shopFunctionsF::getAddToCartButton ($this->product->orderable); 
$html '<input type="submit" name="addtocart" class="ja-addtocart-button" value="'.JText::_('COM_VIRTUEMART_CART_ADD_TO') .'" title="'.JText::_('COM_VIRTUEMART_CART_ADD_TO') .'" />';
echo $html;?>

</span>
<?php ?>

<div class="clear"></div>
</div>
<?php }
 // Display the add to cart button END  ?>

<input type="hidden" class="pname" value="<?php echo htmlentities($this->product->product_nameENT_QUOTES'utf-8'?>"/>
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="view" value="cart"/>
<?php //EDTITED removed noscript// ?>
<input type="hidden" name="task" value="add"/>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>"/>
</form>

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

fgozar

Hi,
find FGOZAR in your code to view fix.
I'm not sure if it work, but your code must be like this:



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">
        <?php //EDTITED FGOZAR ADD js-recalculate CLASS// ?>
<form method="post" class="ja-vm-product js-recalculate" action="<?php echo JRoute::('index.php'); ?>">
                <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 ?>">
<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) and !empty($this->product->prices['salesPrice'])) {
?>


<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 { ?>
<!-- <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 ">
<input type="button" class="quantity-controls quantity-plus"/>
<input type="button" class="quantity-controls quantity-minus"/>
    </span>
<?php // Display the quantity box END ?>

<?php
// Display the add to cart button
?>

<span class="addtocart-button">
<?php //echo shopFunctionsF::getAddToCartButton ($this->product->orderable); 
$html '<input type="submit" name="addtocart" class="ja-addtocart-button" value="'.JText::_('COM_VIRTUEMART_CART_ADD_TO') .'" title="'.JText::_('COM_VIRTUEMART_CART_ADD_TO') .'" />';
echo $html;?>

</span>
<?php ?>

<div class="clear"></div>
</div>
<?php }
 // Display the add to cart button END  ?>

<input type="hidden" class="pname" value="<?php echo htmlentities($this->product->product_nameENT_QUOTES'utf-8'?>"/>
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="view" value="cart"/>
<?php //EDTITED FGOZAR RE-ADD noscript// ?>
<noscript><input type="hidden" name="task" value="add"/></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $this->product->virtuemart_product_id ?>"/>
</form>

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


magelanos

That is what i did the first time but it was not working.

It is only working by removing the noscript. But without functionality of the plus minus signs  :-\

magelanos

Can anyone please help?

i did the change that fgozar was saying "remove the no script" but the thing is that

1) if a order something then it is not removed from the stock
2) i can not place another order of a different color/size optio from the same item in the same order

any help would be gratefull!