13. Jun 2022 |

IADB IT-süsteemide arendus – 6. semester

Kuues ehk viimane semester algas sellega, et oli vaja leida endale praktikakoht. Kuuenda semestri peakski moodustama erialapraktika (24 EAP) ja lõputöö (6 EAP). Kuna ma teadsin, mida ma tahaksin teha – PHP, e-kaubanduse ja e-äri valdkond, mõnes keerukamas raamistikus – siis kandideerisin praktikale Lumavisse. See oli minu esimene valik ja sinna ka sain. Lumavi kõrval oli siiski veel paar ettevõtet varuks.

Praktika algas minu jaoks 31. jaanuaril ja lõppes 27. mail. Praktika oli päris intensiivne õppimine ja tegi kiiresti selgeks, et 2.5 aastat ei anna tegelikult kuigi palju oskuseid ega kuigi palju arusaamist. Seega õppida on veel kõvasti.

Nüüd on teha jäänud veel vaid lõputöö, mille plaanin teha sügissemestril. Ei tahaks, et see kuidagi venima jääks.

4. Jun 2022 |

WooCommerce – add product custom field to order email

What you need, is to use a hook and a function to modify e-mail template. That is it.

First idea probably would be changing the template. In this file: wp-content/plugins/woocommerce/templates/emails/email-order-items.php

First $product = $item->get_product(); and then $key = $product->get_meta('custom_field_key'); and then this thread was helpful but this is the hook and action were what I really needed.

Also useful:

'customer_completed_order' === $email->id and order email ids that are available.

I order to test e-mails locally Sendinblue works really well as SMTP and is simpler to set up than Sendgrid.

26. May 2022 |

Docker, Linux, user

Täielik segadus 🙂 Selleks, et Linuxis saaks Dockeriga lokaalselt php arendust teha, siis peab Docker, host ja PHP õigused paika sättima.

Digital Oceani õpetus täpselt olemas.

To run docker command without sudo, you need to add your user (who has root privileges) to docker group. (ref).

See current user: echo ${UID}

Official doc: Post-installation steps for Linux

You need to run your application as the same uid inside the container as you do on the host to get file ownership to match. (ref)

Something about application and root here.

Digital Ocean tutorial – WordPress with docker compose.
Probably the thing you are looking for – Docker in Development – Docker and File Permissions

12. May 2022 |

FacetWP reindex products automatically (simple solution with wp-cli + cron)

FacetWP had introduced WP-CLI interface which I was very much looking for. Just run wp facetwp index and reindex for the entire site will be created.

I just had a moment in one of my online stores where I saw that the index was last built 8 months ago. Now can add this line to WP All Import bash script and index will be built quickly every time. Or run it once day for example together with daily backup. I find it very convenient.

1. Apr 2022 |

ps aux with grep

Very good ps aux overview can be found on Linode website.

grep stands for global regular expression print

grep by default is case sensitive. Add -i to make it case insensitive.

ps aux | grep -i "robert" | grep -i "vscode" – by such piping you can narrow down the search step by step.

If kill does not then add kill -9 <pid> (source).

history | grep “git commit” | grep “something”

Regular expressions in grep and on youtube basic Grep and Regex and the most useful DO guide

ps aux | grep -i "...be.t"  – simple pattern match.

ps aux | grep -P -i "^weekend"  – add -P to get perl compatible regular expressions to work

ps aux | grep -i '^weekend.*product' – lines that start with weekend and contains word product.

To see your proccesses then ps ux is enough.

13. Mar 2022 |

Russians are killing Ukrainians. 🇺🇦 Please help!

On February 24th 2022 Russians attacked the beautiful, free and democratic Ukraine. Without any reason. And started killing them.

Russians are killing everybody, without selection of their targets – civilians from infants to elderly people. Schools, hospitals, kindergardens, residential areas, nuclear power stations, everything. Russians are carpet bombing cities, also using banned artillery such as cluster bombs.

Please see how you can help Ukraine – supportukrainenow.org

To all the Russians, Belarussians, Armenians: You probably don’t have access to Twitter, Facebook, Reuters, BBC,  Meduza, Bellingcat, Washington Post etc. to get all the reliable information of what is going on in Ukraine and what your guys are up to there. Because it is all censored in your country. And this is can be the only explanation why you are so quiet and ignorant (to say the least).

Luckily, somehow you manage to get on my website. Therefore, I inform you that what you are currently doing in Ukraine is not good. Leave this country alone.  According to social surveys, you seem to support (and support) Putin and this war. Please, stop supporting this war (and Putin)! You have already lost around 50 000 men in this war (in just two weeks) and nobody likes you anyway.

22. Feb 2022 |

Magento REST API – Specified request cannot be processed and Class does not exist

Class \Vendor\ModuleName\Api\TestInterface does not exist

During development move things from local-src + symlink to app/code/{vendor}/{modulename} so that namespace and folder structure could match.

If you are using interfaces in your module then this is also true that you need to use full path reference in PHPdoc instead of use import and reference.

Both worked for me

Specified request cannot be processed

rest/V1/test/ – V in version needs to be capital letter (also in webapi.xml).

And just useful tip that you can extract interface out of existing class.

8. Feb 2022 |

How to install Magento on local nginx

Not a tutorial but notes for myself

Creating vitual host (tutorial), user rights in /var/www/ (rights to group, user to group) and here even better guidance.

Before Magento I usually set up default WordPress installation first to test if php works well, database is ok and nginx has started.

Useful command: sudo mv wordpress/* /var/www/html – how to move content of whole directory somewhere

Order of Magento installation

As it is in the documentation. But you can be sure something goes wrong.

  1. Composer create-project to get the metapackage: composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento/
  2. Permissions, also sudo chown -R rbrt:www-data .  It is occasionally needed later too.
  3. php bin/magento install... (this is very long command you can find here)*
  4. If you need then you can also install sample data: php bin/magento sampledata:deploy (takes very long time) and you may also need to run php bin/magento catalog:images:resize to get the images shown in the store.

Clean Magento install with sample data is 1.4 GB, 109 thousand files (so creating and deleting may take long time), 410 database tables. For comparison, clean WordPress is just 12 tables.

*For this step you need ElasticSearch running. sudo systemctl start elasticsearchInstructions can be found here on Digital Ocean website.

Nginx conf

/etc/nginx/ -> nginx.conf

Restart: sudo systemctl reload nginx

Get ownership
sudo chown -R robert /var/www/html
Give ownership back to the webserver system user www-data.
sudo chown -R www-data:www-data /var/www/html

Conf

Create .conf to /etc/nginx/sites-available

Symlink conf to sites-enabled

sudo ln -s /etc/nginx/sites-available/abc.conf /etc/nginx/sites-enabled/

Symlinked conf updates itself automatically

Add custom domain to hosts file

sudo code /etc/hosts --user-data-dir

Rights

This did not work well…

First, you should ensure that your username is included in www-data group. If not, you can add your username as www-data group
sudo adduser $USER www-data
After that, you should change the ownership of /var/www to your username
sudo chown $USER:www-data -R /var/www

Set file permissions before Magento installation

https://devdocs.magento.com/guides/v2.4/install-gde/composer.html#set-file-permissions – but I am not shure what the before means.

Disable 2FA

php bin/magento module:disable Magento_TwoFactorAuth

Because otherwise you can not log into admin (because mail server does not work)

Post installation commands

php bin/magento setup:di:compile
php bin/magento indexer:reindex or php bin/magento indexer:status
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f
php bin/magento deploy:mode:set developer
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento module:disable Magento_Csp
php bin/magento module:disable Magento_TwoFactorAuth