zyON Posted June 29, 2013 Author Share Posted June 29, 2013 Yes, I tried that after remembering that $page was a reserved word, and used $p instead. I've just pasted the wrong code. but it doesn't work. Link to comment Share on other sites More sharing options...
apeisa Posted June 30, 2013 Share Posted June 30, 2013 trackChange seems to be missing. Link to comment Share on other sites More sharing options...
zyON Posted June 30, 2013 Author Share Posted June 30, 2013 This is the code that I'm actually using: foreach($pages->find("template=bustotorso-especial") as $p) { $p->of(false); $p->trackChange('fullurl'); $p->save(); } The post hook on save is correctly working as when I save a product in the admin the fullurl field is correctly filled. The above code is used on the template and should fill automatically the fullurl for all the already created products using that template (as ryan suggested). Link to comment Share on other sites More sharing options...
ryan Posted July 3, 2013 Share Posted July 3, 2013 If you are still getting that error, I think we need to see the full code for your hook function too (as well as any other code involved in the process). Is the error you are getting specific to the page $p that you are calling $p->save() on? The error you mentioned indicates that something is changing the output formatting state back to on, as it won't throw that error unless you try to save a page that has output formatting on. I am guessing that you need another ->of(false); in your hook function for $brand, but not certain without seeing the full context. Link to comment Share on other sites More sharing options...
zyON Posted July 3, 2013 Author Share Posted July 3, 2013 Ok, so it goes like this: On admin.php I have set up the hook as this: $pages->addHook('saveReady', null, 'storeFullURL'); function storeFullURL($event) { $page = $event->arguments(0); if($page->template == 'manequim') { $page->fullurl = "{$page->parent->url}{$page->gama->name}/{$page->tipo->name}/{$page->colecao->name}/{$page->name}" ; } } On the product template php file (in this case on manequim.php) I have on the top of the page this: foreach($pages->find("template=manequim") as $p) { $p->of(false); $p->trackChange('fullurl'); $p->save(); } The fullurl field is correctly filled if I go to a page on the admin and save it. I'm not getting any error now, the field for the already created pages just doesn't get automatically filled when I load the template file. Link to comment Share on other sites More sharing options...
kongondo Posted July 3, 2013 Share Posted July 3, 2013 <digression>@zyON, am curious as to why you chose to write to admin.php? Is this the one that comes with PW?</digression> Link to comment Share on other sites More sharing options...
zyON Posted July 3, 2013 Author Share Posted July 3, 2013 Yes, I followed Ryan's suggestion. <digression>@zyON, am curious as to why you chose to write to admin.php? Is this the one that comes with PW?</digression> Link to comment Share on other sites More sharing options...
kongondo Posted July 3, 2013 Share Posted July 3, 2013 Yes, I followed Ryan's suggestion. Aah. Sorry missed that. So the question is to Ryan then...why admin.php? Just curious. I thought we should "leave it alone" in most cases? Link to comment Share on other sites More sharing options...
Soma Posted July 3, 2013 Share Posted July 3, 2013 /** * Admin template just loads the admin application controller, * and admin is just an application built on top of ProcessWire. * * This demonstrates how you can use ProcessWire as a front-end to another application. * * Leave this file as-is, do not remove. * */ require($config->paths->adminTemplates . 'controller.php'); This is in site/templates/admin.php Do not remove, doesn't mean you can add code there. It's a easy way to add admin only auto hooks without creating a autoload module. 3 Link to comment Share on other sites More sharing options...
kongondo Posted July 3, 2013 Share Posted July 3, 2013 Soma, Thx for clarification although one could argue "Leave this file as-is" means...... Link to comment Share on other sites More sharing options...
ryan Posted July 6, 2013 Share Posted July 6, 2013 although one could argue "Leave this file as-is" means I'll change that "leave the existing contents as-is, but feel free to add to it." 1 Link to comment Share on other sites More sharing options...
BUCKHORN Posted September 26, 2013 Share Posted September 26, 2013 This addresses the original post. I have built and operated a web shop that did $750 - $1mil in sales per year, so I have some experience in this field. You have categories, brands, and product attributes (like size, color, sex). What you don't want to do is mix these things up. Here's how I would approach this.... Categories -- Shoes ---- Heels ---- Tennis Shoes ---- Boots Your categories do not contain sex or brand, this is stored with the product. Here's what your product fields would look like... ProductTitle ProductCategoryPage (page field type) ProductManufacturerPage (page field type) ProductAttributesRepeater (repeater field type, there may also be a case for page field type. This is where you save things like color, size and sex, and probably sku depending on how your shop is set up) Then when you need to find products you have an efficient and flexible way to do so.... Find products in category boots where manufacturer equals brand $pages->find('category=boots,manufacturer=brandname') Find all products by brand then display by category $pages->find('manufacturer=brand') Find all products by color and sex $pages->find('attributes.color=orange,attributes.sex=women') Find all products by sex and category $pages->find('category=shoes,attributes.sex=men') I think it was mentioned, but I would also use url segments and a central controller to handle the page requests (a controller to build the product listing depending on values in the url segments). Just keep an eye your sql queries for performance. In some cases it may be better to use multiple smaller queries and filter the data in your loop. You may also need to use the autojoin feature on some of these fields, but I don't fully understand autojoin yet, so it may not do what I expect. 1 Link to comment Share on other sites More sharing options...
peterfoeng Posted January 21, 2014 Share Posted January 21, 2014 Hi everyone, Thanks for this discussion, I find this pinned thread really helpful I am setting up a simple shop in Processwire and I am wondering if anyone has idea how to do "Shopify product variant" but in PW style (screenshot from Shopify attach) maybe using combination of repeater / pages fieldtype. I am just wondering Thank you Link to comment Share on other sites More sharing options...
blackeye1987 Posted September 8, 2014 Share Posted September 8, 2014 couldn't you check if the option is already in your "size" category (page which contains all sizes so far typed by users)if not create a new page inside that category (category chosen by selectbox)the input can be exploded and then cycled through after posting the data.your structure should be thenProduct Categories -Color --red --black --green -size --m --s --xxl even if the answer is quiet late hope it helps anyway Link to comment Share on other sites More sharing options...
Mass Harry Posted February 3, 2015 Share Posted February 3, 2015 this categories& product <div class="header_bottom_left"> <div class="categories"> <ul> <h3>Categories</h3> <?php foreach ($pages->get(1022)->children as $c) { $class = $c->url === $page->url ? " class='active'" : ''; echo "<li $class><a href='$c->url'>$c->title</a></li>"; } ?> </ul> </div> </div> <div class="header_bottom_right"> <?php foreach ($page->children as $child):?> <div class="grid_1_of_4 images_1_of_4 product_category"> <a href="<?php echo $child->url; ?>"><img src="<?php echo $child->product_image->first()->url; ?>" alt="" /></a> <h2><?php echo $child->title; ?></h2> <div class="price-details"> <div class="price-number"> <p><span class="rupees">Rp <?php echo $child->sc_price; ?></span></p> </div> <div class="add-cart"> <h4><a href="<?php echo $child->url; ?>">View</a></h4> </div> </div> </div> <?php endforeach; ?> </div> <div class="clear"></div> Link to comment Share on other sites More sharing options...
kongondo Posted February 3, 2015 Share Posted February 3, 2015 @Mass Harry, There is no need to double post. I will delete your other post Please use the 'forum post code function' to format your code. It is really difficult to follow what you've posted Even so, I haven't seen a question in there. What exactly is your question? Link to comment Share on other sites More sharing options...
adrianmak Posted February 13, 2015 Share Posted February 13, 2015 zyON, Check into the Page Fieldtype Maybe something like this for organization: Shoes -- Men ---- Product A ---- Product B ---- Product C -- Women ---- Product A ---- Product B ---- Product C Brands (these are just the references, no products listed as children) -- Brand 1 -- Brand 2 -- Brand 3 Collections (these are just the references, no products listed as children) -- Collection A -- Collection B -- Collection C Create page fields for Brand and Collection, and add them to your "Product" template. Now you can associate brand and collection with each product. So to get the output you need: Shoes > Men (Any Brand) $pages->get("/shoes/men/") Shoes > Brand2 $pages->find("has_parent=/shoes/, brand.title=Brand 2") Shoes > Brand2 > CollectionB $pages->find("has_parent=/shoes/, brand.title=Brand 2, collection.title=Collection B") You could also pass $input values to the selector so this could be generated via use selections. This setup good enough for a site selling one kind of product. How about multiple kinds of product ? for example an apparel store, computer store Link to comment Share on other sites More sharing options...
renobird Posted February 13, 2015 Share Posted February 13, 2015 You can apply the same concepts to multiple product types. Either nest them under a larger parent /products/ or create additional roots parents for other types /apparel/ and /computers/ You question is a bit too general for me to give a detailed answer. Every product catalog has it's own specific set of requirements, so there isn't really a one-size-fits-all answer. Link to comment Share on other sites More sharing options...
adrianmak Posted February 13, 2015 Share Posted February 13, 2015 which implementation is better for different queries mysite.com/brandname mysite.com/product-type mysite.com/men mysite.com/women using URL segment or create each of them with a page Link to comment Share on other sites More sharing options...
itsmonika Posted January 4, 2022 Share Posted January 4, 2022 Thanks for sharing this. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now