Jump to content

Shopping Cart and repeater fields


Claus
 Share

Recommended Posts

Hi there!  :) I’m using Apeisa’s ShoppingCart module to do a little shop. I have pages each with a range of products as repeater items. These items have different prices (package deals, individual products and so on). They all render with correct names and prices. So far so good!

Now the issue: When I add one or more products to the cart I get the $title of the $page instead of the product name, and the price is set to the price of the first product on the page no matter which product I add to the cart. So I’m doing something wrong.

Here is the code I’m using:

// Primary content is the repeater fields of "sc_item"
$contentThree = '';

//sc_item is my repeater field
foreach ($page->sc_item as $product) {
	$contentThree .= "<span class='sc_item'>" . $product->sc_name . "</span></br>";
	$contentThree .= "<span class='sc_price'>" . $modules->get( "ShoppingCart" )->renderPrice( $product->sc_price ) ."</span> excl. BTW (VAT)";
	$contentThree .= "<span class='sc_add'>" . $modules->get("ShoppingCart")->renderAddToCart(). "</span>";
}

$contentThree .= $modules->get("ShoppingCart")->renderCart();

Can anyone point me in the right direction?

Link to comment
Share on other sites

Okay, one bonus question: I can’t figure out how to get the names of the repeater items to appear after I have added them to the shopping cart. Instead I get the title of the page, which I am guessing ShoppingCart presumes is the product proper, for each of the added items. How can get the name of each added item instead? I’ve tried to see what I could find in the module, but only got as far as this: https://github.com/apeisa/Shop-for-ProcessWire/blob/master/ShoppingCart.module#L219 and as I read it, the module should automatically construct the names from the page/product name plus the repeater-name (l. 222).

Link to comment
Share on other sites

Okay, so I figured it out. I have individual products as repeater fields on a given product page, and each of these items have a full name. So I went to line 219 of ShoppingCart.module and replaced the section with this:

$title = $product->sc_name;

… and I now get the correct title of each item.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...