See product in Add to Cart Modal - How?

  • Posts: 152
  • Thank you received: 1
12 years 5 months ago #54757

Hi Guys,

I've been busy working on a few ecommerce sites lately ad Hika is the best! I just love this component. Supprt is outstanding and its such a mind-leap from the other stuff...

But I have a small issue I really need some help with - though if I can figure it out before I get a reply I'll let everyone know.

What I want is for the product which has been "Add to Cart" to display in the modal window just below the 2 buttons (Notices) So I know I'm looking in the notices.php under checkout... Quesiton is - what code to I put and where?

Thank you
Brett


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 5 months ago #54819

Hi,

Actually, in the popup, you don't know which product was added.

All you can do is load the cart and get the name of the product which was added the latest in the cart. Something like that:

$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
 if($product->cart_product_modified>@$max->cart_product_modified){
  $max = $product;
 }
}
if($max){
 $class = hikashop_get('class.product');
 $product = $class->get($max->product_id);
 echo $product->product_name;
}

Last edit: 12 years 5 months ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 5 months ago #54867

Hiya Nicolas,

Ah yeah I see how it's working and I've added the code - I can now see the product name... How can I pull more info from the cart though - it would be great if I could get a picture of the item, along with the name and the price - is that possible? I've tried grabbing some of the code from view > checkout > cart but its just breaking the thing - probably because my PHP syntax is poor/ faulty


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 5 months ago #54952

Well, you can do like that:

foreach($cart->products as $product){
 if($product->product_id!= $max->product_id) continue;
 echo $product->prices[0]->price_value;
 $image = reset($row->images);
 $height = $this->config->get('thumbnail_y');
 echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 4 months ago #55399

Hi Nicolas,

I think I'm doing something wrong here... From what I can see I replace the original snippet from foreach... but then nothing is being echoed back:

<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;


foreach($cart->products as $product){
if($product->product_id!= $max->product_id) continue;
echo $product->prices[0]->price_value;
$image = reset($row->images);
$height = $this->config->get('thumbnail_y');
echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}

?>

She's not working....


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 4 months ago #55499

You should not replace it but add it to the other.
See, the $max variable which is used in the second piece of code I gave is initialized in the first piece of code I gave.

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 4 months ago #55509

Hi Nicolas,

Unfortunately that also has some issues >

Take 1 >


<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
if($product->cart_product_modified>@$max->cart_product_modified){
$max = $product;
}
}
if($max){
$class = hikashop_get('class.product');
$product = $class->get($max->product_id);
echo $product->product_name;
}
foreach($cart->products as $product){
if($product->product_id!= $max->product_id) continue;
echo $product->prices[0]->price_value;
$image = reset($row->images);
$height = $this->config->get('thumbnail_y');
echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}

?>


Errors:

Strappy Chick2100
Warning: reset() expects parameter 1 to be array, null given in /home/content/97/9350797/html/templates/ds_2/html/com_hikashop/checkout/notice.php on line 44

Fatal error: Call to a member function display() on a non-object in /home/content/97/9350797/html/templates/ds_2/html/com_hikashop/checkout/notice.php on line 46

Take 2 >

<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
if($product->cart_product_modified>@$max->cart_product_modified){
$max = $product;
}
}
if($max){
$class = hikashop_get('class.product');
$product = $class->get($max->product_id);
echo $product->product_name;
foreach($cart->products as $product){
if($product->product_id!= $max->product_id) continue;
echo $product->prices[0]->price_value;
$image = reset($row->images);
$height = $this->config->get('thumbnail_y');
echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}
}
?>

Errors:

Strappy Chick2400
Warning: reset() expects parameter 1 to be array, null given in /home/content/97/9350797/html/templates/ds_2/html/com_hikashop/checkout/notice.php on line 43

Fatal error: Call to a member function display() on a non-object in /home/content/97/9350797/html/templates/ds_2/html/com_hikashop/checkout/notice.php on line 45



I dont know whats going on here....


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 4 months ago #55581

Take1, the line:
$image = reset($row->images);

should be:
$image = reset($product->images);

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 4 months ago #55642

hmmm... Still no joy on this one

Here is my code:

<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
if($product->cart_product_modified>@$max->cart_product_modified){
$max = $product;
}
}
if($max){
$class = hikashop_get('class.product');
$product = $class->get($max->product_id);
echo $product->product_name;
}
foreach($cart->products as $product){
if($product->product_id!= $max->product_id) continue;
echo $product->prices[0]->price_value;
$image = reset($product->images);
$height = $this->config->get('thumbnail_y');
echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}

?>

here is the error:

Fatal error: Call to a member function display() on a non-object in /home/content/97/9350797/html/templates/ds_2/html/com_hikashop/checkout/notice.php on line 46

Although on the positive side it is now showing price total I think


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 4 months ago #55746

Ah yes, the image helper in not loaded on that view... You need to load it yourself like that:

$this->image = hikashop_get('helper.image');

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 4 months ago #56853

Hi Nicolas,

This is great I have it working nicely now - thank you. here is the working code so far:

<div id="modalcart">    
    <div class="modalmodel">
<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
if($product->cart_product_modified>@$max->cart_product_modified){
$max = $product;
}
}
if($max){
$class = hikashop_get('class.product');
$product = $class->get($max->product_id);
echo $product->product_name;
}
?>
</div>
    <div class="modalprice"><strong>Price: </strong>
<?php
foreach($cart->products as $product){
 if($product->product_id!= $max->product_id) continue;
 echo $product->prices[0]->price_value;
?>
</div>
<?php
 $this->image = hikashop_get('helper.image');
 $image = reset($product->images);
 $height = $this->config->get('thumbnail_y');
 echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}
?>

  </div>
  
</div>

I do still have one issue though... If I add a product with options ie. its a shoe site and you could select a black or grey or white shoe - when I add it - in the modal it has a bit of a freak out with the price... please see here > heelcrush.com/collection.html (Click Modern Crimp "BUY ME") Select a size and "BUY ME" in the modal that pops up the price is now crazy >> Price: 300.00000

Please help me :)


Believe in Better
Last edit: 12 years 4 months ago by nowherenowhere.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 4 months ago #56879

Change :
echo $product->prices[0]->price_value;

to:
$class = hikashop_get('class.currency');
echo $class->format($product->prices[0]->price_value,$product->prices[0]->price_currency_id);

Last edit: 12 years 4 months ago by nicolas. Reason: fixing code

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 4 months ago #56892

Nah Nicolas, shes not working m8... See here:

<div id="modalcart">    
    <div class="modalmodel">
<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
if($product->cart_product_modified>@$max->cart_product_modified){
$max = $product;
}
}
if($max){
$class = hikashop_get('class.product');
$product = $class->get($max->product_id);
echo $product->product_name;
}
?>
</div>
    <div class="modalprice"><strong>Price: </strong>
<?php
foreach($cart->products as $product){
 if($product->product_id!= $max->product_id) continue;
      $class = hikashop_get('class.currency');
echo class->format($product->prices[0]->price_value,$product->prices[0]->price_currency_id);
?>
</div>
<?php
 $this->image = hikashop_get('helper.image');
 $image = reset($product->images);
 $height = $this->config->get('thumbnail_y');
 echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}
?>

  </div>
  
</div>

I get this error:

Parse error: syntax error, unexpected T_CLASS in /home/content/97/9350797/html/templates/ds_2/html/com_hikashop/checkout/notice.php on line 48

Not sure what this all means is it because there are 2 variables called $class


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 4 months ago #56923

Use that code instead:
$class = hikashop_get('class.currency');
echo $class->format($product->prices[0]->price_value,$product->prices[0]->price_currency_id);

The following user(s) said Thank You: nowherenowhere

Please Log in or Create an account to join the conversation.

  • Posts: 152
  • Thank you received: 1
12 years 4 months ago #56974

Yeah that worked well thank you Nicolas :)

Here is the code for all the other peeps who need it >>

<div id="modalcart">    
    <div class="modalmodel">
<?php
$class = hikashop_get('class.cart');
$cart = $class->loadFullCart();
$max = null;
foreach($cart->products as $product){
if($product->cart_product_modified>@$max->cart_product_modified){
$max = $product;
}
}
if($max){
$class = hikashop_get('class.product');
$product = $class->get($max->product_id);
echo $product->product_name;
}
?>
</div>
    <div class="modalprice"><strong>Price: </strong>
<?php
foreach($cart->products as $product){
 if($product->product_id!= $max->product_id) continue;
      $class = hikashop_get('class.currency');
echo $class->format($product->prices[0]->price_value,$product->prices[0]->price_currency_id);
?>
</div>
<?php
 $this->image = hikashop_get('helper.image');
 $image = reset($product->images);
 $height = $this->config->get('thumbnail_y');
 echo $this->image->display($image->file_path,true,$image->file_name,'style="margin-top:10px;margin-bottom:10px;display:inline-block;vertical-align:middle"');
}
?>

  </div>
 
</div>


Believe in Better

Please Log in or Create an account to join the conversation.

  • Posts: 2
  • Thank you received: 0
11 years 3 weeks ago #130616

Hello.

Is it possible to pass to the notice even the related products to the added one?

I can pass a module position to the popup but if i try to add related items module to this doesnot work (custom html in the module shows, so the module position added i functional)

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 2 weeks ago #130799

Hi,

Do you have an error displayed ?
You can enable the Joomla debug mode, and set the error reporting to maximum to see from where the problem come.

Please Log in or Create an account to join the conversation.

Time to create page: 0.118 seconds
Powered by Kunena Forum