Jump to content

a-ok

Members
  • Posts

    812
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

a-ok's Achievements

Hero Member

Hero Member (6/6)

97

Reputation

10

Community Answers

  1. I've added the following to the config.js file, which works, but it then overrides any settings in the Processwire UI... CKEDITOR.editorConfig = function( config ) { config.allowedContent = true; config.allowedContent = { script:true }; };
  2. Can anyone help me to allow <script></script> tags in CKEditor? It's for an inline cookie consent that needs to be added within a ckeditor text field. I can't figure it out at all from either PW docs or CKEditor docs. Thanks.
  3. Apologies if this has been asked before but I'm a little stumped. This also be more of a general-PHP question but was curious if Processwire offered anything to make this more efficient? I have a PageReference field on a product template and the client can select as many references for the template "products-code-option" as they wish. These are organised in the CMS as products-code-section (parent) then products-code-option (child). See screenshot. Anyway, my question is I'd like to build an array sorting the pages selected into their parent titles. $result = array(); foreach ($page->products_codes as $option) { $result[$option->parent->name]["title"] = $option->parent->title; $result[$option->parent->name][] = $option; } bdb($result); This is what I have so far, which kind of works, but it's not adding the options into a single array but rather their own array for each option (see last screenshot). Any thoughts where I'm going wrong?
  4. Yes but I thought the headers `X-Shopify-Topic` etc would be included in the response. but it's not? `file_get_contents("php://input")` returns the raw data, which is good, but no way of checking the headers on this? Sorry I'm just a bit confused.
  5. I used `php://input' to test with and it's returning the data from the Shopify hook of the product updated etc. $test = json_decode(file_get_contents("php://input"), true); Is there any way to do this using the PW API and if not is it possible to get the headers so I know what X-Shopify-Topic is being requested?
  6. @elabx 4 years ago you posted this and it's still tripping me up! I now have a Shopify webhook firing to /api/ in my PW app when a product is updated. I have verified that PW is getting the response with the following... $log->save('shopifyApi', 'Webhook triggered from Shopify'); Great! The request is a POST request so I'm assuming I use `$input->post()` but I am unsure how to check the headers to see what the X-Shopify-Topic is and also to grab the data? Attached below is the webhook response tested on request catcher...
  7. This does work! I'm sorry for the clearly amateur question! Thanks!
  8. I've added a page hook method (addHookMethod) in ready.php and I am calling it on a page. Simple enough. See below for the current code. I now need to pass parameters into the hook but can't figure out how this is possible? So with the current usage here: $product = $page->shopifyGetProductById(); I'd like to pass some parameters into the hook to then use within the hook function itself: $product = $page->shopifyGetProductById($data); wire()->addHookMethod('Page::shopifyGetProductById', function($event) { $page = $event->object; $gid = "gid://shopify/Product/{$page->shopifyProductId}"; $query = <<<GQL query { product(id: "$gid") { title } } GQL; $result = wire('cache')->get("shopifyGetProductById{$page->shopifyProductId}"); if (!$result) { $result = shopifyGQL($query); wire('cache')->save("shopifyGetProductById{$page->shopifyProductId}", $result, "template=shopifyProduct, shopifyProductId={$page->shopifyProductId}"); } $event->return = $result; });
  9. I tend to use $cache to cache JSON in the database, which is great, but I need to return HTML markup from a JS fetch and I'm unsure how to use PW to return cached HTML. Below is how I do it for JSON but could anyone lend a hand for HTML? $segments = array($input->urlSegment1, $input->urlSegment2, $input->urlSegment3); $data = array(); if ($segments[0] === 'v1' && $segments[1] === 'portfolio') { $response = $cache->get('apiPortfolio'); if (!$response) { $portfolio = array(); $projects = $pages->find("template=project, sort=-date"); if (count($projects)) { foreach ($projects as $project) { $portfolio[] = array( 'id' => $project->id, 'title' => $project->title ); } } $response = $portfolio; $cache->save('apiPortfolio', $response, "template=portfolio"); } $data['response'] = $response; } else { header('Content-Type: text/html'); throw new Wire404Exception(); } $dataJson = wireEncodeJSON($data); header('Content-Type: application/json'); echo $dataJson;
  10. I was also looking to see if I could do it with JSON so output the data using PW to JSON then supplying that either to an API or plugin...
  11. Thanks @dragan – I tried to find some decent APIs but couldn't find anything decent... are you aware of any? And yes I was looking at the headless Chrome stuff too but was quickly confused haha!
  12. Is there a modern way to create PDF on the fly these days with the data from PW? mPDF seems fairly old school and only supports tables etc but was looking for something that supports flexbox/css grid etc. I could just use a print stylesheet but it needs to download a PDF, ideally, on click. Any thoughts? I've had a look at RockPdf and Pages2Pdf but wondered if there was anything else? Thanks! Rich
  13. I ended up using Guzzle to do, for example, the following: // Shopify init function shopifyQL($query) { $shopifyHost = "xxxxx.myshopify.com"; $shopifyPassword = "xxxxx"; $graphqlEndpoint = "https://$shopifyHost/admin/api/2021-01/graphql.json"; $client = new \GuzzleHttp\Client(); $response = $client->request('POST', $graphqlEndpoint, [ 'headers' => [ 'Content-Type' => 'application/json', 'X-Shopify-Access-Token' => $shopifyPassword, 'X-Shopify-Api-Features' => 'include-presentment-prices' ], 'json' => [ 'query' => $query ] ]); $json = $response->getBody()->getContents(); $body = json_decode($json, true); $data = $body['data']; return $data; } // Get Shopify shop defaults (useful for currency checks) wire()->addHookMethod('Page::shopifyShop', function($event) { $page = $event->object; $query = <<<GQL query { shop { name primaryDomain { url host } } } GQL; // Get cache only if it's less than or equal to 1 month $result = wire('cache')->get('shopifyShop', WireCache::expireMonthly); if (!$result) { $result = shopifyQL($query); wire('cache')->save('shopifyShop', $result, WireCache::expireMonthly); } $event->return = $result; });
  14. I've been having a play... and I'm getting somewhere but passing the query itself is something I'm struggling with. I might end up using Guzzle but thought I'd see if it was possible using PW natively. // Shopify init $shopifyHttp = new WireHttp(); $shopifyHost = "xxxx.myshopify.com"; $shopifyPassword = "xxxx"; $shopifyHttp->setHeaders([ 'Content-Type' => 'application/json', 'X-Shopify-Access-Token' => $shopifyPassword, 'X-Shopify-Api-Features' => 'include-presentment-prices' ]); $shopifyBase = "https://$shopifyHost/admin/api/2021-01/graphql.json"; $query = <<<GQL query { shop { name primaryDomain { url host } } } } GQL; bdb($shopifyHttp->post($shopifyBase, [ 'query' => json_decode($query) ])); Any thoughts? I've tested the POST request in Postman and works and this was the PHP HTTP code for that... <?php require_once 'HTTP/Request2.php'; $request = new HTTP_Request2(); $request->setUrl('https://xxxxx.myshopify.com/admin/api/2021-01/graphql.json'); $request->setMethod(HTTP_Request2::METHOD_POST); $request->setConfig(array( 'follow_redirects' => TRUE )); $request->setHeader(array( 'X-Shopify-Access-Token' => 'xxxxx', 'Content-Type' => 'application/json', 'Cookie' => '_shopify_fs=2021-03-31T10%3A14%3A46Z; _y=82249b91-c91c-4631-8cb9-2a859e3e756e; _s=5be7df5e-f9a6-45a9-a472-e7f262f54a8b; _shopify_y=82249b91-c91c-4631-8cb9-2a859e3e756e; _shopify_s=5be7df5e-f9a6-45a9-a472-e7f262f54a8b' )); $request->setBody('{"query":" query {\\n shop {\\n name\\n primaryDomain {\\n url\\n host\\n }\\n }\\n }","variables":{}}'); try { $response = $request->send(); if ($response->getStatus() == 200) { echo $response->getBody(); } else { echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' . $response->getReasonPhrase(); } } catch(HTTP_Request2_Exception $e) { echo 'Error: ' . $e->getMessage(); }
×
×
  • Create New...