News:

Looking for documentation? Take a look on our wiki

Main Menu

add to cart from within cart pricelist does not work

Started by brandiware, March 21, 2017, 19:21:46 PM

Previous topic - Next topic

brandiware

Hi all,

not sure if this is my ignorance or a bug. When trying to add a product using the below code nothing happens.
The $error variable is empty.
Anything missing here ?

I added the code just before the iteration of the carts product, rendering them onto the cart page.

The code will add a product which comes free based on the actual list of products in the cart.

<?php
$i = 1;
$moertelSumme = 0;

  $moertelProductIDs = array();
  $moertelProductIDs[0] = 1967;
  $moertelProductIDs[1] = 39;
   $this->cart->add($moertelProductIDs,$error);
           
           
foreach ($this->cart->products as $pkey => $prow) {
   $prow->prices = array_merge($prow->prices,$this->cart->cartPrices[$pkey]);
?>

brandiware

sorry, it was my ignorance. The product ids were the culprits

$moertelProductIDs[0] = '1967';
  $moertelProductIDs[1] = '39';

Milbo

Uhm,.. I wonder myself why it insists on a string, should also work with an integer. Interesting observation, which php version?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

brandiware

Hi Milbo,

the php is 5.6.18. I can not reliably add and remove products from the cart. I guess I am not using the same functions as called when the update icon is clicked.
The add and remove works by means of updating quantities yet the changes are not consistently made visible.

Any help is greatly appreciated. Once this all works I can publish a responsive version of the cart.

Here is what I do from within my override of default_pricelist.php:

Add a product:

        $this->cart->add($moertelProductIDs,$error);
       $this->cart->updateProductCart($moertelProductIDs,$error);

Delete a product (the quantity is changed to zero but the product still appears):

    $existing_haltermoertel[]=$prow->virtuemart_product_id;
   $this->cart->removeProductCart($existing_haltermoertel);
   $this->cart->updateProductCart($existing_haltermoertel);

From the remark in the updateProductCart func I take it that the removal of 0 qty products is not implemented. Hence there must be another function to call
since hitting the delete icon works.

   public function updateProductCart() {

      $quantities = vRequest::getInt('quantity');
      if(empty($quantities)) return false;
      $updated = false;

      foreach($quantities as $key=>$quantity){
         if (isset($this->cartProductsData[$key]) and !empty($quantity) and !isset($_POST['delete_'.$key])) {
            if($quantity!=$this->cartProductsData[$key]['quantity']){
               $this->cartProductsData[$key]['quantity'] = $quantity;
               $updated = true;
            }

         } else {
            //Todo when quantity is 0,  the product should be removed, maybe necessary to gather in array and execute delete func
            unset($this->cartProductsData[$key]);
            $updated = true;
         }
      }

      $this->setCartIntoSession(true);
      return $updated;
   }

Milbo

" that the removal of 0 qty products is not implemented."
That works.

I think you buy some support from me and talk with me about another strategy to solve your problem. It looks like you unecessary hack the core.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

brandiware

Hi Milbo, I was unaware that default_pricelist.php is part of the core. I can override it.

I would very much appreciate support from you on this issue as well as the issue with many multi-variants.
I still get crashes when using multi-variants above 100. Debug Mode and PHP Developer mode don't produce
any error messages. VM simply reverts to the home page.

When can we set up a support session and how ? Could we use teamviewer ?
Let me know how I can buy this support.

Best Regards
Stefan

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

brandiware

Hi Milbo, I have created a ticket with a 1 hour support now. Waiting for your contact.

My Skype is Stefan Brandmeier