Adding item to cart, URL changes, but its same page

  • Hi all,

    Yesterday I had an issue where the product page wasn't showing the product detail, I added the following rewrite rule

    Code
    1. RewriteRule ^shop/([a-zA-Z0-9-]+)/?$ /shop/product.php?s=$1 [L]


    So today, working on the next step, adding an item to the cart.


    First question, can the cart page be /shop/cart/index.php or do I need to have /shop/cart.php and then have a rewrite rule?


    I ask this because, currently when I add an item to the cart, the URL changes to /shop/cart/ but its still the product page, but it not showing the product details.

    Cart page:

    PHP
    1. <?php perch_shop_cart([ 'template' => 'cart/cart.html', ]); ?>


    Debug message after item has been added to the cart:


    find_by_path(): "> [1] SELECT * FROM perch3_pages WHERE pagePath='/shop/product.php' LIMIT 1
    get(): "> [48] SELECT DISTINCT settingID, settingValue FROM perch3_settings WHERE userID=0
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=14
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=14
    add_to_cart(): "> [1] SELECT itemID, itemQty FROM perch3_shop_cart_items WHERE cartID=14 AND productID=0
    find(): "> [1] SELECT * FROM perch3_shop_products WHERE productID=0 AND productDeleted IS NULL LIMIT 1
    add_to_cart_from_form(): ">Limiting based on stock.
    calculate_cart(): ">------------------------------ Calculating cart ------------------------------
    get_cart_field(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=14
    calculate_cart(): "> [1] SELECT * FROM perch3_shop_cart WHERE cartID=14
    find(): "> [1] SELECT * FROM perch3_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
    get_value(): "> [1] SELECT locationID FROM perch3_shop_tax_locations WHERE locationIsHome=1 LIMIT 1
    find(): "> [1] SELECT * FROM perch3_shop_tax_locations WHERE locationID=1 AND locationDeleted IS NULL LIMIT 1
    find(): "> [1] SELECT * FROM perch3_shop_currencies WHERE currencyID=47 LIMIT 1
    calculate_cart(): "> [1] SELECT COUNT(productID) AS product_count, SUM(itemQty) AS item_count FROM perch3_shop_cart_items WHERE cartID=14
    recalculate_summary_data(): ">Tax mode: exc
    get_by(): "> [1] SELECT * FROM perch3_shop_cart_items WHERE cartID=14 ORDER BY itemID ASC
    find(): "> [1] SELECT * FROM perch3_shop_products WHERE productID=1 AND productDeleted IS NULL LIMIT 1
    find(): "> [1] SELECT * FROM perch3_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
    get_value(): "> [1] SELECT r.rateValue FROM perch3_shop_tax_group_rates gr, perch3_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
    find(): "> [1] SELECT * FROM perch3_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
    get_value(): "> [1] SELECT r.rateValue FROM perch3_shop_tax_group_rates gr, perch3_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
    find_matching(): "> [1] SELECT z.* FROM perch3_shop_shipping_zones z LEFT JOIN perch3_shop_shipping_zone_countries c ON z.zoneID=c.zoneID WHERE z.zoneActive=1 AND z.zoneDeleted IS NULL AND (c.countryID=236 OR zoneIsDefault=1) ORDER BY zoneIsDefault ASC LIMIT 1
    get_all_flat(): "> [1] SELECT * FROM perch3_shop_shippings WHERE shippingDeleted IS NULL ORDER BY shippingOrder ASC
    find_set(): "> [1] SELECT * FROM perch3_shop_shipping_zones WHERE zoneDeleted IS NULL AND zoneActive=1 AND zoneID IN (1)
    get_edit_values(): "> [1] SELECT rateID AS id, rateTitle AS title, rateValue AS rate, locationID FROM perch3_shop_tax_rates WHERE rateDeleted IS NULL ORDER BY rateValue DESC
    {closure}(): ">Qualifying shipping method ‘Post Office’
    find(): "> [1] SELECT * FROM perch3_shop_shippings WHERE shippingID='1' AND shippingDeleted IS NULL LIMIT 1
    calculate_cart(): ">Using shipping zone: United Kingdom
    find(): "> [1] SELECT * FROM perch3_shop_tax_groups WHERE groupID=1 AND groupDeleted IS NULL LIMIT 1
    get_value(): "> [1] SELECT r.rateValue FROM perch3_shop_tax_group_rates gr, perch3_shop_tax_rates r WHERE gr.rateID=r.rateID AND gr.groupID=1 AND gr.locationID=1
    get_currently_active(): "> [nil] SELECT * FROM perch3_shop_promotions WHERE promoFrom<='2019-02-22 10:51:00' AND promoTo>'2019-02-22 10:51:00' AND promoActive=1 AND promoDeleted IS NULL ORDER BY promoOrder ASC
    update(): ">UPDATE perch3_shop_cart SET cartTotalItems='5', cartTotalProducts='1', cartTotalWithTax='1202.33', cartTotalWithoutTax='999.95' WHERE cartID='14'
    insert(): ">INSERT INTO perch3_shop_cart_data(cartID,productID,cartData) VALUES('14','','{\"product\":\"\"}')
    get_filtered_listing_from_index(): "> [nil] SELECT tbl.* FROM ( SELECT idx.itemID, main.*, idx2.indexValue as sortval FROM perch3_shop_index idx JOIN perch3_shop_products main ON idx.itemID=main.productID AND idx.itemKey='productID' JOIN perch3_shop_index idx2 ON idx.itemID=idx2.itemID AND idx.itemKey='productID' AND idx2.indexKey='_id' WHERE 1=1 AND ((idx.indexKey='slug' AND idx.indexValue='basket')) AND idx.itemID=idx2.itemID AND idx.itemKey=idx2.itemKey GROUP BY idx.itemID, idx2.indexValue, productID ) as tbl WHERE (productDeleted IS NULL AND productStatus=1 AND parentID IS NULL) GROUP BY itemID, sortval ORDER BY sortval ASC
    set(): ">Using template: /templates/shop/products/product.html
  • I believe this is related to my issue yesterday and my lack of knowledge when it comes to rewrite rules.


    If I change things so that the cart page is /shop/cart.php it works - but the rewrite rule i have for the product page is making the following URL not work - /shop/cart/


    Code
    1. RewriteRule ^shop/([a-zA-Z0-9-]+)/?$ /shop/product.php?s=$1 [L]


    I didn't realise the issues were related when I created this post Drew.

    I will need to work out a rewrite rule that covers /shop/basket/ and /shop/checkout/ and any others that are part of the process - has anyone got a htaccess file they can share?

  • Obviously I don't know your structural layout but what I was trying to get at earlier was that at the moment you only have a small handful of rules in place. The trouble is your previous rule is being matched when you try go to the cart, therefore it's redirecting to the product page.


    Here is an example of a vanilla perch shop access file from an old project:

    You'll note how my shop product rewrites are near the bottom to avoid them being picked up and overruling the other rewrites. Now I am by no means an expert and this could well be a messy example, but hopefully it helps you.