Jump to content


  • Posts

  • Joined

  • Last visited

ric355's Achievements


Newbie (1/14)



  1. Some help needed please. I want to be direct people to my newsletter subscription page as part of a promotion. After people have signed up to the newsletter I want to be able to direct them to a product suggestion, but I also want to retain the standard message "Thank you for subscribing to our newsletter" so that it is clear why the user has ended up at that page (which is generated from verification.php in the ps_emailsubscription module). I have e-mail verification turned on to get this last step. I'm not at all sure how to achieve this, I basically just want to extend the message a bit more (that bit I can do), and then add a product to the blank area on the page which can then be clicked on to open up the detail as elsewhere on the site. I'm happy to hard code the product id as it's only one product I want to point them at presently. I'm using the classic template, prestashop 1.7. Can anyone give some guidance please?
  2. I was testing a new store just prior to launch, using Prestashop, and came across a problem whereby if I added several items to my basket and checked out, the final order summary on the browser shows the same image for every item purchased. It always shows the image of the last item listed. Having spent some time debugging it, I ended up in src/Adapter/Order/OrderPresenter.php in the function getProducts. I'm a complete novice with Prestashop but not a novice developer, so I have a poor understanding of what this code is actually doing, other than it seems to be copying data from the cart to a structure to represent the order, but was able to come up with a change to work around the problem. There's a loop going through each product in the order, with a nested loop within it going through the cart: private function getProducts(Order $order) { $cart = new Cart($order->id_cart); B> $orderProducts = $order->getCartProducts(); $cartProducts = $this->cartPresenter->present($cart); $orderPaid = $order->getCurrentOrderState() && $order->getCurrentOrderState()->paid; foreach ($orderProducts as &$orderProduct) { $orderProduct['name'] = $orderProduct['product_name']; $orderProduct['price'] = $this->priceFormatter->format($orderProduct['product_price'], Currency::getCurrencyInstance((int)$order->id_currency)); $orderProduct['quantity'] = $orderProduct['product_quantity']; $orderProduct['total'] = $this->priceFormatter->format($orderProduct['total_price'], Currency::getCurrencyInstance((int)$order->id_currency)); if ($orderPaid && $orderProduct['is_virtual']) { $id_product_download = ProductDownload::getIdFromIdProduct($orderProduct['product_id']); $product_download = new ProductDownload($id_product_download); if ($product_download->display_filename != '') { $orderProduct['download_link'] = $product_download->getTextLink(false, $orderProduct['download_hash']) . '&id_order=' . (int)$order->id . '&secure_key=' . $order->secure_key; } } foreach ($cartProducts['products'] as $cartProduct) { if ($cartProduct['id_product_attribute'] === $orderProduct['id_product_attribute']) { if (isset($cartProduct['attributes'])) { $orderProduct['attributes'] = $cartProduct['attributes']; } else { $orderProduct['attributes'] = array(); } $orderProduct['cover'] = $cartProduct['cover']; $orderProduct['unit_price_full'] = $cartProduct['unit_price_full']; } } OrderReturn::addReturnedQuantity($orderProducts, $order->id); } $orderProducts = $this->cartPresenter->addCustomizedData($orderProducts, $cart); return $orderProducts; } I've picked out the nested loop, as I think this is where the problem is: foreach ($cartProducts['products'] as $cartProduct) { if ($cartProduct['id_product_attribute'] === $orderProduct['id_product_attribute']) { if (isset($cartProduct['attributes'])) { $orderProduct['attributes'] = $cartProduct['attributes']; } else { $orderProduct['attributes'] = array(); } $orderProduct['cover'] = $cartProduct['cover']; $orderProduct['unit_price_full'] = $cartProduct['unit_price_full']; } } Here it's going through every item in the cart, and checking id_product_attribute to find the matching item in the order. I don't know what specifically that value represents but in my case they all seemed to be zero (those I checked at least). Every time it finds a match it reassigns the cover image and the unit_price_full value with the item from the cart. Since the individual items in the basket all have id_product_attribute of zero, they all match each other. This causes the cover image to be constantly overwritten, so the resulting image you get is of the last item that was processed, which is always the last one on the order. To fix this on my own website I've added an additional check to make sure the product id is the same; if ($cartProduct['id_product'] === $orderProduct['id_product']) $orderProduct['cover'] = $cartProduct['cover']; I'm pretty sure this fixes it but I suspect it is not the most ideal way to deal with it. Rather the cover images should probably be assigned in a different loop. One of the reasons I've raised this is because I was a bit concerned about the "unit_price_full" attribute also being continuously overwritten as it may well be a bug also. I did try a test but the prices seem to be preserved correctly unlike the images. I can only assume that the template uses a value from a different structure when it displays the summary. I'm assuming there are loads of people who know how this stuff works in much more detail and can comment whether there is a better way of fixing it or whether I'm way off the mark.
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More