Jump to content


  • Posts

  • Joined

  • Last visited

Everything posted by John_A

  1. Thanks both for your input. As I said, it was a bespoke shopping cart script, that I inherited, which already had a Google feed but the sizes were in a comma separated list for each product (used to be OK with Google) but now needs to be one size per product. I wrote neither the initial script nor the google feed add-on. I've been tasked with this, and not a lot of time to do it. I'm already working on a local dev server, not the live site. TBH it would have taken me longer to do everything you suggest to ask the question "properly" than it did for me to fix it myself. I didn't explode the commas because the CSV list is built from another query on the database for the prodID, all individual rows as product options for size, so didn't see the point in building it again then exploding it to get back to where I started. It's a CSV in the original as that used to be OK with Google. I'm pretty sure I gave as much information as was needed to answer / help if someone was inclined to. In fact I posted a duplicate elsewhere, and it was answered with a solution - too late for me but it looked like it would have worked. Hey ho. Lesson learnt.
  2. OK, thanks for your help so far. Partially thanks to your input I changed my approach completely, now manipulating the feed as I create it line by line later in the same file, rather than messing with the array beforehand, and have it working just as I need. Hopefully, one day, I'll be as awesome as you and not need to ask for help. Stay safe, and thanks again!
  3. Going through the array for sizes was messing with the feed output later on, so I changed it to a foreach instead. The plan is for the first foreach loop to manipulate the product array as necessary, then once done a separate foreach going through the now correct array to output the feed. Here's the one I need to fix: - foreach ($result as $key => $thisProduct) { echo $thisProduct["prodID"] . '<br/>'; $thisproductSizes = ""; $sizesResult = $dbA->query("SELECT $ExtraFieldsValues.content From $ExtraFields, $ExtraFieldsValues Where $ExtraFields.name = 'size' and $ExtraFields.extraFieldID = $ExtraFieldsValues.extraFieldID and $ExtraFieldsValues.productID =".$thisProduct["prodID"]." Order By $ExtraFieldsValues.position"); $sizesCount = $dbA->count($sizesResult); for ($sf2 = 0; $sf2 < $sizesCount; $sf2++) { $sizesRecord = $dbA->fetch($sizesResult); $thisproductSizes .= ",".$sizesRecord["content"]; } if (strlen($thisproductSizes) > 0){ // there's at least one size so needs to be dealt with $thisproductSizes = substr($thisproductSizes,1); // do stuff here to make one product into many // each with item_group_id = prodID, // and id = prodID-xx (size), with only one size } else { $thisproductSizes = ""; } echo $thisproductSizes . '<br />'; } But, thinking about it, if there's only 1 size that's fine, it's if there's 2 or more that there'll be an issue...
  4. There probably is but it's for an automatic google product feed that will run once every month so efficiency isn't really a concern. It's part of a bespoke ecommerce script I inherited and can't really change much on, the table structures are what they are and can't be changed at this stage. So what I have is the $products array which includes most of the fields I need straight out of it, but the sizes needs to be a 2nd query within that. The $product array should be updated on-the-fly with duplicates where necessary with only one size in each, and the id and item group id updated too.
  5. It turns out I don't actually have the sizes in the $product array as above, they're a query within the loop that builds the feed in it's current state. $result is the query to fetch all products... $count = $dbA->count($result); for ($f = 0; $f < $count; $f++) { $record = $dbA->fetch($result); $productSizes = ""; $result2 = $dbA->query("SELECT $ExtraFieldsValues.content From $ExtraFields, $ExtraFieldsValues Where $ExtraFields.name = 'size' and $ExtraFields.extraFieldID = $ExtraFieldsValues.extraFieldID and $ExtraFieldsValues.prodID =".$record["prodID"]." Order By $ExtraFieldsValues.position"); $count2 = $dbA->count($result2); for ($f2 = 0; $f2 < $count2; $f2++) { $record2 = $dbA->fetch($result2); $productSizes .= ",".$record2["content"]; } if (strlen($productSizes) > 0){ $productSizes = substr($productSizes,1); } echo $productSizes . '<br/>'; } The $products array includes the other fields I referenced above along with quite a few others: - but does NOT include the item group id field, which should be added blank or populated as above for each product. I'm not sure if this makes it easier, or harder?
  6. I have an existing PHP array ($products) with various fields in it.... id / title / description / link / image link etc. etc. as per requirements for a Google Products feed (https://support.google.com/merchants/answer/7052112). My issue is that, for clothing, Google want a separate record for each size available. My array includes the "size" field as a comma separated list e.g. 6,8,10,12,14 or XS,S,M,L,XL etc. etc. So before creating the feed (a text file, which is currently outputting fine except for the size field issue) I need to duplicate each id where there's more than 1 size in that field, for each size, and then manipulate the fields a little so that (ignoring all the duplicated fields that would remain unchanged) instead of the single record : - id size item group id 52 6,8,10,12,14,16,18,20,22,24,26 I'd have 11 records, item group id would be what the id is, the size appended to the id, and the size field only one (in sequence of those from the original), so: - id size item group id 52-6 6 52 52-8 8 52 . .. ... 52-24 24 52 52-26 26 52 That's just one product....there are quite a lot, each with multiple sizes, but all in the same format within the $products array. As always, any help / pointers / solutions much appreciated!
  7. Nothing, everything is the same there are just slight differences in the way things are done sometimes, e.g. parsing xml as php the syntax is slightly different in .htaccess due to PHP setups differing slightly. 99.9% of the time everything is identical, but there are sometimes a few lines in a .htaccess file somewhere that just have to differ. I'm perfectly happy with the hosting I have, I pay for a managed service and it was actually myself who asked for Litespeed on the one in question, initially when it was touted as a faster, drop-in replacement for Apache but it's now evident that there are a few (rare cases) where things have to be done a little differently. I'm happy with the speed improvements that has brought, but at the same time don't want to mess with my dev server at this time as I have other sites live elsewhere that are not on Litespeed but use the same dev server. Anyway, it is what it is and I am where I am. I'm quite happy with my setup (dev and multiple live servers), I don't do anything over-complicated. It worked perfectly before this issue (for 10+ years) and hopefully using requinix's solution it will continue to do so - it's no great hardship going forward if I occasionally need to make a .htaccess.dev file if there's a difference between dev and production. All I asked for was a way to quickly clone the existing .htaccess files as per the OP
  8. OK, here's the background... I used to use an environment variable to enable me to differentiate between my dev and production server, using this in .htaccess: - <IfDefine DEV_SERVER> # dev server specific stuff here </IfDefine> <IfDefine !DEV_SERVER> # production server specific stuff here </IfDefine> The environment variable "DEV_SERVER" was only ever set on my dev server, and never on production, obviously. This approach worked a treat until my production server host installed Litespeed as a replacement for Apache. Litespeed doesn't like the above, and ignores everything. I tried having different versions of .htaccess files for dev and production, but that's messy and dangerous, I like to be able to interchange all files at any time between the two. My dev server runs Apache 2.4 and I have no plans to change this. I read that you can specify a different filename for .htaccess by putting this in httpd.conf: - AccessFileName .htaccess.dev But (I think) you can't set an order of preference here (like, say, DirectoryIndex), so I'm thinking the simplest solution so that I can have identical copies is have my dev server use .htaccess.dev instead of .htaccess - the production server will simply ignore any .htaccess.dev files. If there's no difference (there doesn't always need to be, it depends on the site and htaccess requirements) then the .htaccess (if there is one) can just be copied and renamed. The dev server will use .htaccess.dev and the live server will still use .htaccess. Problem is, I've manually done some already and so that's why if there is already a .htaccess.dev file then it should be left as is. ETA: I realise this is now no longer a PHP problem, even though my first thought was to do it with a PHP script, it seems that was probably the more complicated approach.
  9. Wow, if that works then that's excellent, thanks a lot! I'll backup all just in case!
  10. Around 200! It is just a 1 off though.
  11. I've got a dev server which, for reasons I won't go into, needs to have different .htaccess files for each site (and subfolders within them) within it. But not always. What I need to do is: - For the folder I put the PHP script in, and every folder under it (the whole tree under it): - If there's a .htaccess file an no .htaccess.dev file, copy .htaccess and name the copy .htaccess.dev (and look in subfolders) If there's a .htaccess file and also a .htaccess.dev file, do nothing (but keep looking for subfolders) If there's neither a .htaccess or .htaccess.dev file, do nothing (but keep looking for subfolders) I'd try to come up with something myself, but getting it wrong will be fairly catastrophic! I'm sure the conditional copy / rename bit is relatively straightforward, but it's the recursive searching of the whole file-system under the script's location that I'm not sure about... Any help greatly appreciated, as always! I have SSH access, if it's easier done that way maybe I'm approaching it wrong?
  12. Thank-you both! I went with option #2, as it seemed the most straightforward. Worked perfectly
  13. I have a file in the same location as my PHP file, say test.txt, and in multiple locations it has content like: - href="http://www.domain.com/entry.php/256/1/this-is-the-title" or href="http://www.domain.com/entry.php/123/2/another-title" which I need replaced within the file to: - href="{EntryNumber=256.link}" and href="{EntryNumber=123.link}" Only the first number is needed for the replacement, it will be between 1 and 999. Everything between the 5th / and the 2nd " can be safely ignored and removed. This is not the only content in the line, and sometimes there may be more than one occurrence per line. I've got this so far: - $buffer = ""; $fp = file($file); foreach($fp as $line){ $buffer .= preg_replace(***struggling with this bit***); } fclose($fp); echo $buffer; file_put_contents($file, $buffer); Am I along the right lines generally? And I have no idea what the preg_replace should be as my regex is a bit trial and error, more error in this case... As always, any help greatly appreciated! EDIT: If it matters, the largest file I need to edit is 39Kb, and includes 175 occurrences of the replacements.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.