oma

Members
  • Content count

    477
  • Joined

  • Last visited

Community Reputation

50 Excellent

About oma

  • Rank
    Sr. Member

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

3,922 profile views
  1. Yep, sorry. Front end template. I could use a count() but it's getting a count of the repeater matrix's type that's 'text' only.
  2. Bit of an odd one here. I'm using a RepeaterMatrix which has various 'types' (text, image, video etc) and on the last iteration of one of the types (text) I want to add an element (for example, a share element... but this has to come after the last text type... not the last RepeaterMatrix row). I'm struggling a bit on how to achieve this? Is there a way to count the total 'text' types then create a PHP count and if the two match then it'll show? foreach ($page->flexible_content as $content) { if ($content->type === 'text') { // } elseif ($content->type === 'images') { // } }
  3. As I am saving the product ID of the Shopify product to each page... I ended up building an array of all the pages that currently exists on Shopify, with the product ID as the key, then I imploded that array by "|" then created a nonActiveProducts pageArray using $nonActiveProducts = wire('pages')->find("shop_detail_shopify_id!=$activeProducts"); What this does is return all the pages that exist in PW that's shopify ID doesn't match the active products... so this returns all the pages that need to be deleted. So, my final question is... is there a method to delete all the pages returned by a pageArray (rather than looping through each and deleting?)
  4. Thanks for the reply. It is currently saving the product ID in a field (in order to load the product detail data) – it's creating the pages fine it's just I cannot work out how to delete the pages that no longer exist in the endpoint list of products (once they remove it from Shopify).
  5. Anyone have any thoughts on this? Just need to work out how to delete the pages that aren't in the JSON but on PW...
  6. Hi folks, I'm going to be using a combination of Shopify's JS Buy SDK (to display the products and add to cart etc) and their API endpoint response to generate the pages required on PW (to match the products on Shopify). The idea is that I'll have two PW templates; one for the Shop overview and then one for the individual detail pages. These will both use the JS Buy SDK to either fetchAll products or fetch a specific product. Obviously the pages on PW need to be created from an endpoint response and thus updated (delete or added to) when new products are removed/added on Shopify. My plan was to do something similar to this forum post: https://processwire.com/talk/topic/16064-create-pages-from-json-feed/ where I would "use a lazy cron function to automatically query the API endpoint every 24 hours. To delete pages that are no longer contained in the JSON response you can collect all of the unique identifiers in the response and then use a PW selector to get pages not matching any of those identifiers. Those pages you delete." I think this sounds good and I have the understanding of it... but I have a couple of questions that I am currently stuck on. Using the PW API... what would be the best way to update the pages based on the returned result? Would it be to loop through the products and check if they exist... if not then create it? I'm unsure how to reverse this to then check if a page exists in the feed that's not on PW then delete it? function myHook(HookEvent $event) { $http = new WireHttp(); $host = 'XXX'; $shopify_api = 'XXX'; $shopify_password = 'XXX'; $shopify_base = 'https://' . $shopify_api . ':' . $shopify_password . '@' . $host . '/admin/products.json'; $products = $http->getJSON($shopify_base); foreach ($products['products'] as $product) { $productID = $product['id']; $productHandle = $product['handle']; $p = wire('pages')->get("shop_detail_shopify_id=$productID"); if (!$p->id) { // If it doesn't exist, create it $p = new Page(); $p->template = 'shop-detail'; $p->parent = '/shop/'; $p->name = $productHandle; $p->title = $product['title']; $p->shop_detail_shopify_id = $productID; $p->of(false); } $p->save(); } } wire()->addHook('LazyCron::every30Minutes', null, 'myHook');
  7. This seemed to have done the trick, Tom! Thanks!
  8. Hi all I have the hook written below... and it works fine on pages that have already been created (when I click 'Save') but when I try to create a new page it throws an error that I can't seem to get by. It appears to be firing this at the title entry point and not at the first 'Save/Publish' option once the client has finished editing. Any thoughts? ProcessPageAdd: Can't save field from a new page - please save the entire page first function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail $today = strtotime("now"); $dateRepeater = $page->events_detail_dates; $lastRow = $page->events_detail_dates->last(); $page->set("events_detail_dates_final_date", $lastRow->events_detail_dates_end_date); $page->save("events_detail_dates_final_date"); } } wire()->addHookAfter('Pages::saveReady', null, 'myHook');
  9. Thanks, Robin. I had used $image->removeVariations(); later after posting and it still didn’t help. Is this what you meant?
  10. I've had a look at a lot of the forum posts relating to the gamma correction on images and I've followed some examples and declared this in my config file. $config->imageSizerOptions = array( 'upscaling' => true, 'cropping' => true, 'quality' => 100, 'sharpening' => 'none', 'defaultGamma' => -1 ); But when comparing the original uploaded image, and the resized image, it still seems to be altering the image a lot. I have even changed this directly in /wire/config.php in case it was related to my setup but this still doesn't work. You can see the difference in images here: http://plh.dk/site/assets/files/2554/natalia-1.760x950.jpg and http://plh.dk/site/assets/files/2554/natalia-1.jpg (original) Any thoughts? I have created new resized sizes to test (so it builds the new images based on this new config change) but, again, it doesn't seem to affect anything. I have also set up the options directly on the usage in the template but, again, doesn't seem to affect the image (http://plh.dk/site/assets/files/2554/natalia-1.720x900.jpg). $options = array( 'quality' => 100, 'sharpening' => 'none', 'defaultGamma' => -1 ); $image = $person->contact_team_image->size(720, 900, $options);
  11. I believe when using 'filter->()' it's using IDs? So I had to do... $limit = 18; $articles = $pages->find("template=where-to-go-detail|our-guides-detail, sort=sort, limit=$limit"); if ($input->get("tags")) { // If GET ?tags= exists... $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $articles->filter("tags.name=$currentTags"); // Append original query with the tags selector if (!count($articles)) throw new Wire404Exception(); }
  12. What I can't work out is why this wouldn't work? $limit = 18; $articles = $pages->find("template=where-to-go-detail|our-guides-detail, sort=sort, limit=$limit"); if ($input->get("tags")) { // If GET ?tags= exists... $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $articles->filter("tags={$currentTags}"); // Append original query with the tags selector if (count($articles)) { continue; } else { throw new Wire404Exception(); } }
  13. Thanks, Robin. I have come up with the following on my overview template (replacing the setup for URL segments and replacing it with a GET setup) $limit = 18; $query = "template=where-to-go-detail|our-guides-detail, sort=sort, limit=$limit"; if ($input->get("tags")) { var_dump($input->get("tags")); $currentTags = $input->get("tags"); $currentTags = $sanitizer->text($currentTags); $query .= ", tags={$currentTags}"; $articles = $pages->find($query); } else { $articles = $pages->find($query); } What do you think? Looks good? I would then use isset($currentTags) to check if a tag has been queried.
  14. I’m guessing this isn’t possible. I’ve had a bit of a play and would need the URL to allow for more than one word in one segment and don’t think that’s possible?
  15. Sorry to bring this up again but felt it was best to keep it under the same topic. I'm wondering if it's possible to do the same with multiple categories? Obviously this line would need to change... $current_category = $categories->get("name=$segment_1"); Any thoughts? Obviously the categories returns would be piped (for example, music|art) is that right? I don't mind using ids either... but just curious to know if you think it's possible.