Author Topic: Add To Cart From Category [Solved]  (Read 264963 times)

legal

  • Beginner
  • *
  • Posts: 13
    • Parfumi
Add To Cart From Category [Solved]
« on: September 15, 2011, 13:22:05 pm »
SOLVED: Add To Cart In Category View


Code: [Select]
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<?php // Product custom_fields
if (!empty($this->product->customfieldsCart)) {  ?>

<div class="product-fields">
<?php foreach ($this->product->customfieldsCart as $field)
?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><b><?php echo  JText::_($field->custom_title?></b></span>
<?php echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
<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 style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><b><?php echo JText::_($field->field->custom_title?></b></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 ?>

<div class="addtocart-bar">

<?php // Display the quantity box ?>
<!-- <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" name="quantity[]" value="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 // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

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

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<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 $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>

EDIT by Forum Mod
Check post #128 by Aspero81/Bartek
and post #144 by Siristru
and post #175 by Marttyn

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10278
  • VirtueMart Version: 3+
Re: Add the "add to cart" button to the category view
« Reply #1 on: September 15, 2011, 19:41:00 pm »
ok, let me see how to get this working

I do NOT do development work for hire.

mojino

  • Beginner
  • *
  • Posts: 15
Re: Add the "add to cart" button to the category view
« Reply #2 on: September 16, 2011, 09:34:01 am »
Hello.
I have exactly the same problem with the same results: "There was an error while updating your cart."
Could you help us?
Thanks.

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10278
  • VirtueMart Version: 3+
Re: Add the "add to cart" button to the category view
« Reply #3 on: September 16, 2011, 12:43:03 pm »
change joomla templates, and see what happens
I do NOT do development work for hire.

legal

  • Beginner
  • *
  • Posts: 13
    • Parfumi
Re: Add the "add to cart" button to the category view
« Reply #4 on: September 16, 2011, 13:02:49 pm »
change joomla templates, and see what happens

Still don't work for me.

legal

  • Beginner
  • *
  • Posts: 13
    • Parfumi
Re: Add the "add to cart" button to the category view
« Reply #5 on: September 16, 2011, 13:39:46 pm »
Now I have update my virtuemart to latest version (2.0.0-RC-2G) and now I don't get error, but it's still don't work.

When I click Add to Cart I get this:
1 was added to your cart.

But there is nothing in my cart (only some product without name, price,...).

mojino

  • Beginner
  • *
  • Posts: 15
Re: Add the "add to cart" button to the category view
« Reply #6 on: September 17, 2011, 11:36:55 am »
The same issue for me.
Please, Help.

legal

  • Beginner
  • *
  • Posts: 13
    • Parfumi
Re: Add the "add to cart" button to the category view
« Reply #7 on: September 17, 2011, 11:49:09 am »
Ok I finally figure it out. Problem was when php want to call product ID and Name. If you copy all code from /components/com_virtuemart/views/productdetails/tmpl/default.php, this piece of code can't call product ID or Name (<?php echo $this->product->virtuemart_product_id ?>), what you have to do is very simple, just delete "this->" so you get this: <?php echo $product->virtuemart_product_id ?>

Or just copy the code bellow:

Code: [Select]
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<?php // Product custom_fields
if (!empty($this->product->customfieldsCart)) {  ?>

<div class="product-fields">
<?php foreach ($this->product->customfieldsCart as $field)
?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><b><?php echo  JText::_($field->custom_title?></b></span>
<?php echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
<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 style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><b><?php echo JText::_($field->field->custom_title?></b></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 ?>

<div class="addtocart-bar">

<?php // Display the quantity box ?>
<!-- <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" name="quantity[]" value="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 // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

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

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<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 $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>

Hope this will work for everybody

legal

  • Beginner
  • *
  • Posts: 13
    • Parfumi
Re: Add the "add to cart" button to the category view
« Reply #8 on: September 17, 2011, 11:58:46 am »
And here is just add to cart button without everything else:

Code: [Select]
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<div class="addtocart-bar">
<?php // Display the quantity box ?>
<!-- <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 style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
</span>

<?php // Display the quantity box END ?>

<?php // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

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

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<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 $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>

And here is the code for add to cart button with quantity chooser:
Code: [Select]
<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<div class="addtocart-bar">

<?php // Display the quantity box ?>
<!-- <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" name="quantity[]" value="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 // Add the button
$button_lbl JText::_('COM_VIRTUEMART_CART_ADD_TO');
$button_cls ''//$button_cls = 'addtocart_button';
if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
$button_lbl JText::_('COM_VIRTUEMART_CART_NOTIFY');
$button_cls 'notify-button';
?>


<?php // Display the add to cart button ?>
<span class="addtocart-button">
<input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
</span>

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

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<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 $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>

mojino

  • Beginner
  • *
  • Posts: 15
Re: Add the "add to cart" button to the category view [Solved]
« Reply #9 on: September 18, 2011, 19:16:30 pm »
ok. It works!!!
Thank you very much.

elvencedor

  • Beginner
  • *
  • Posts: 3
Re: Add the "add to cart" button to the category view [Solved]
« Reply #10 on: September 20, 2011, 07:03:12 am »
THNKS
but this doesn't show product custom fields  :(

elvencedor

  • Beginner
  • *
  • Posts: 3
Re: Add the "add to cart" button to the category view [Solved]
« Reply #11 on: September 20, 2011, 07:10:28 am »
ок, Task with customfieldsCart cart solved with replace in your code
$this->product->
to
$product->

Now we need to solve the problem with simple customfields of product - how to show it on category page...

elvencedor

  • Beginner
  • *
  • Posts: 3
Re: Add the "add to cart" button to the category view [Solved]
« Reply #12 on: September 20, 2011, 07:15:54 am »
It's Ок
To show some customfields of product not related to cart on category page we can use this code
Code: [Select]
<?php // Product custom_fields
if (!empty($product->customfields)) {  ?>

<div class="product-fields">
<?php foreach ($product->customfields as $field)
?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>">
<span class="product-fields-title" ><b><?php echo  JText::_($field->custom_title?></b></span>
<?php echo JHTML::tooltip($field->custom_tip,  JText::_($field->custom_title), 'tooltip.png'); ?>
<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 ?>

mojino

  • Beginner
  • *
  • Posts: 15
Re: Add the "add to cart" button to the category view [Solved]
« Reply #13 on: September 21, 2011, 14:00:39 pm »
Another small problem is that when you click on the button to add a product, instead of adding only one product, it adds two at a time (if you have 1 and click on the add button, the counter goes directly to 3 instead of 2 and then 5, 7, etc.)

Awerso

  • Jr. Member
  • **
  • Posts: 67
Re: Add the "add to cart" button to the category view [Solved]
« Reply #14 on: September 21, 2011, 22:01:15 pm »
I also have the same problem as stated above. Also if you add a product in the category view I only get the message: "1 undefined was added to your cart" Not the product name