Forum
issues with perch_shop_cart
Hi,
I'm trying to integrate the shop app into my site (running on MAMP locally) and have hit difficulties when trying to add to, and display, the cart on a page. I have created a php page (index.php) for the main shopfront inside a folder called shop (which is located in the root directory of the site along with home.php contact.php etc. This is the same as I did for the Blog App. The shop index page is displaying products correctly as per the list.html template. However, when I attempt to add to cart (with the default action="shop/cart") I get an error that the URL doesn't exist on the server. So I tried creating a php file / page for the cart and adding the perch_shop_cart() php line to it (see cart.php below), then directing the list.html form action to cart.php. This returns a completely blank page with a php 500 internal server error. If I remove the command from cart.php to display the cart, the page displays blank but but appears (minus the cart obviously) only after hitting refresh. I can only assume that there is a way that the shop needs to be integrated that I've missed somewhere. As I say I've based the process on the instructions for installing the blog as there is only a tutorial covering initial install of shop. Which worked fine. Please let me know what obvious mistake I've made!
DIAGNOSTICS
Perch: 3.0.8, PHP: 7.0.15, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (3.0.8), assets (3.0.8), categories (3.0.8), perch_blog (5.5), perch_forms (1.9), perch_shop_orders (1.2.2), perch_shop_products (1.2.2), perch_shop (1.2.2), perch_members (1.6.2)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_blog', 'perch_members', 'perch_shop', ); ?>
PERCH_LOGINPATH: /cms
PERCH_PATH: /Users/Andy/Desktop/LB2/cms
PERCH_CORE: /Users/Andy/Desktop/LB2/cms/core
PERCH_RESFILEPATH: /Users/Andy/Desktop/LB2/cms/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: 0c66c2e1f82f9e0b7617b2cb8270f2c7
Resource folder writeable: Yes
HTTP_HOST: localhost:8888
DOCUMENT_ROOT: /Users/Andy/Desktop/LB2
REQUEST_URI: /cms/core/settings/diagnostics/
SCRIPT_NAME: /cms/core/settings/diagnostics/index.php
SHOP INDEX
<?php include('../cms/runtime.php');
perch_layout('global.header');
?>
<!-- calls the products template from list.html-->
<?php perch_shop_products(); ?>
<!-- footer-->
<div class="footer-basic">
<footer>
<div class="social"><a href="#"><i class="icon ion-social-instagram"></i></a><a href="#"><i class="icon ion-social-snapchat"></i></a><a href="#"><i class="icon ion-social-twitter"></i></a><a href="#"><i class="icon ion-social-facebook"></i></a></div>
<ul class="list-inline">
<li><a href="#">Home </a></li>
<li><a href="#">Contact </a></li>
<li><a href="#">FAQ </a></li>
<li><a href="#">Terms</a></li>
<li><a href="#">Privacy Policy</a></li>
</ul>
<p class="copyright">Let's Bake© 2017</p>
</footer>
</div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.8.2/js/lightbox.min.js"></script>
</body>
</html>
PRODUCTS LISTING (list.html)
<perch:before>
<div class="wrapper cols2-nav-right">
<div class="primary-content">
<h1>Products</h1>
<ul class="listing">
</perch:before>
<li>
<a href="/shop/products/<perch:shop id="slug" type="slug" />/">
<perch:shop id="title" type="text" />
</a>
<perch:categories id="category" set="products" label="Category">
<perch:category id="catTitle" />
</perch:categories>
<perch:if not-exists="has_variants">
<perch:form id="add_to_cart" app="perch_shop" action="/shop/cart.php"> <!--have tried both this and just the "/shop/cart" default. default causes error of URL not found-->
<perch:input id="product" type="hidden" value="<perch:shop id="productID" env-autofill="false" />" />
<perch:input type="submit" value="Add to cart" />
</perch:form>
</perch:if>
</li>
<perch:after>
</ul>
</div>
</div>
CART PHP
<?php include('../cms/runtime.php');
perch_layout('global.header');
?>
<?php perch_shop_cart()?>
<!--have tried calling cms runtime from various folder levels ../../ etc. no luck-->
<div class="footer-basic">
<footer>
<div class="social"><a href="#"><i class="icon ion-social-instagram"></i></a><a href="#"><i class="icon ion-social-snapchat"></i></a><a href="#"><i class="icon ion-social-twitter"></i></a><a href="#"><i class="icon ion-social-facebook"></i></a></div>
<ul class="list-inline">
<li><a href="#">Home </a></li>
<li><a href="#">Contact </a></li>
<li><a href="#">FAQ </a></li>
<li><a href="#">Terms</a></li>
<li><a href="#">Privacy Policy</a></li>
</ul>
<p class="copyright">Let's Bake© 2017</p>
</footer>
</div>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightbox2/2.8.2/js/lightbox.min.js"></script>
</body>
</html>
If you look in your error log, it'll tell you what the error is.
I'm getting this in the error log. Any help would be appreciated.
For some reason it's not finding your product. What can you tell me about product ID 6?
Hi Drew,
I'm not sure where the ID is from. I added a product to the shop through the admin as per the instructions for installation just to get things up and running. Is there somewhere you think I should look specifically to get more detail for you? Perhaps I did or didn't do something when adding the products?
Is that not the product you're trying to add to the cart?
Yes, sorry, there's only one product at the moment.
I've tried to delete and add a new product to see if the issue cleared but no joy. The error log is the same but with the new product ID of 7 (as expected). I've looked at /PerchShop_Cart.class.php:723 which shows as the following,
I've tried fiddling with various tax options, stock levels etc but no change.
Do you have prices set for the selected currency?
Hi Drew, I've set currency to GPB and entered a price for the product of 1.00
Is the error still the same?
Hi Drew, prices were already set before. Sorry wasn't clear on that. Yes the error is still there and is the same.
What else can you tell me? I can't see why this wouldn't work from the information I have.
This error appears when I go to the single product view in my product.php page. Not sure if it's relevant?
On another note, would the file structure of the site affect things? I have a folder called shop in the root directory with three files index.php , cart.php and product.php. All of the Perch templates displayed on those pages are kept in the Perch/Templates/Shop folder (including cart.html) where they were originally?
Yes, how are you calling
perch_shop_product()
?This is product.php to display the product. It does show the product with the various things such as the price etc. and again from there add to cart goes to the blank page.
And this is product.html
Okay, so crucially, this was not a code issue. Something had gone wrong within the database on the local server. I created a new database and the problem seems to have gone away. Apologies if I've caused any wasted head scratching time! Thanks for all of your help, I wouldn't have got there If I hadn't gone back and started from scratch!