Wednesday, 18 March 2020

Installing Stripe for magento 2

On this occasion and in some future posts for brevity I will cut the extraneous text and just list the sequence of commands I had to follow / steps taken. I find when following other peoples' guides I get frustrated when the extra "fluff" distracts me from the few commands I need to enter. Explanations will be given where needed, but no fluff.


1. Download the plugin from https://stripe.com/docs/plugins/magento/install#download
I downloaded the composer version

2. Place the file in the same directory as your composer.json. Typically this is the root magento folder. Copy it by FTP or whatever.

3. SSH into the machine or if a dev instance using docker then docker exec -it <magento2dev> bin/bash to get to the console (I test using docker - I will document this later also, highly recommended).

4. Switch to the folder you put the file in and tar -xvf stripe-magento2-x.x.x.tgz

5. composer require stripe/stripe-php:^6


  • 6. php bin/magento setup:upgrade
  • php bin/magento cache:flush
  • php bin/magento cache:clean
7
  • php bin/magento setup:di:compile 
  • php bin/magento setup:static-content:deploy
  • php bin/magento setup:static-content:deploy


Then go to the backend and configure it from stores->configuration.

Starting and stopping magento batch duties.

As we are learning about magento 2, we are becoming increasingly aware that many of the tasks that worked fine on magento 1 don't always seem to want to work on magento 2. Exporting CSV files, bulk editing items, it simply doesn't work, with messages telling you these actions are queued on various lists. Even if you have cron configured correctly it still doesn't work.

Well, this is a note to remember how to start services, I will add as I discover new issues and the corresponding services.

1. Export CSV doesn't start.


2. Bulk edit attributes product grid, doesn't start processing.

You need to start: bin/magento queue:consumer:start product_action_attribute.update


Tuesday, 12 November 2019

Magento 2 catalog page images taking too long to load and failing.

If you've upgraded or cleared the image caches for magento 2, you may notice that every catalog page loads the images at a snail pace, and if you have any load balancers that restrict php processes (like hypernode does), it may not load more than say 9 images on the page before giving up and showing broken links.

The short version of why this is happening, is because after you clear the cached thumb/small/etc images, you are only left with base images at full size (at least as far as magento is concerned) and so every time it wants to display a smaller image, it has to reprocess it on the fly, this uses php code, and this is why we encounter problems, we're asking too much of magento and a server by using more than our share of php processes to convert every single image on the catalog page.

You can obviously minimise the issue by limiting the items per page to 9 or 12 or whatever, but this is a workaround not a solution.

As it happens, magento has thought about this and provided a function to "pre-warm" the image cache and generate all the necessary images in all sizes.

You should know that a) you need shell access and b) you need a while (on our server, 10k products took about 4 hours).

The function is as follows. You should really only be doing this if you are familiar with the magento binary.



/bin/magento catalog:images:resize


Pretty simple, when you know, and when it works.

Thursday, 9 May 2019

Magento 2 - Attention! Something went wrong!

Something went wrong with processing the default view and we have restored the filter to its original state.

So says the product grid in the backend of Magento 2 when you're innocently trying to edit stuff.
This is something to do with filtering although I don't entirely (yet) know how to trigger it.

The Fix: 


Well, looking around, I found this page on stackexchange which has a couple of solutions, but for me the solution appears (because you never want to fully commit in magento 2!) to solve this.

Go to phpmyadmin, table admin_user, and figure out the user_id of the affected user by just looking at the table. Write that down.

Then go to table ui_bookmark and find the row for any other user_id, copy the contents of key config for namespace product_listing identifier current, into the same field of the affected user_id

Or to try to put it simply, copy across the contents of the config field from one that works for another user. 



I feel like you ought to be able to just delete the line for the affected user_id too, as I notice they're not generated for pages you haven't looked at before, so it should regenerate it, but I felt that my way of copying the data would be safer without looking at how the code works.

This field contains a load of information on which fields were last sorted and filtered it seems. Resetting that with good data fixes this, without having to clear any caches or reindex.

Looks harder than it is, trust me.

Oh and don't forget to backup your database first!

Update: 


It kept happening. Digging a bit further it seems it's being caused or partly caused by having "sku" to "Null" on some values in the catalog_product_entity table.

props to this site for figuring that out somehow

If you go into phpmyadmin, load up catalog_product_entity, and sort based on sku column, you might (probably will!) see some values of SKU with "Null".

The reason this happened is because in magento 1 at least, if you duplicate a product, it creates a duplicate with blank SKU. If you then save it and don't enter an SKU, or don't save it, I think you get these null sku products.

Hmm.

Magento 2 fun!

Well, I wouldn't really call it fun, honestly.
It's now May 2019, Magento 2 was released, or perhaps we should say it escaped, several years ago, so I thought it must be ready for production, surely.

Well, depends on your opinion I guess.

Anyway - this blog is getting revived - because it needs to be. Here goes.

Woop.

Tuesday, 6 August 2013

Editing Magento's Checkout Success Page - A Great Tip (Stop the page from clearing on refresh!)

Here's a great tip I picked up. On checkout completion, the page shows once with "Checkout Success" etc.

However, when you press F5 or refresh, you get dumped to an empty cart and have to go through the whole thing again.

But you can stop this.

Go to:

app\code\core\Mage\Checkout\controllers\OnepageController.php

and comment out line 227:

//$session->clear();

Now, next time you go through checkout, you can refresh the page as much as you like, and get all your CSS layout, xml, etc all sorted in one go.

Fantastic.

Don't forget to change it back though!!

Tuesday, 11 June 2013

Adding a CMS static block into nearly any page (example: cms block on contact us page)

Easier than it sounds, this. It only works with phtml files, I think.

1) Go to your backend, cms -> static blocks. Create a block with the content you wish to display and the important bit, NOTE the Identifier, that's the key we use to call the block.
In this example I created a block and called it "contactusblock".

2) Open the phtml file, in this case app\design\frontend\<yourname>\default\template\contacts\form.phtml

Add:


<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('contactusblock')->toHtml() ?>


anywhere you like in the phtml file.

Clear any caches, etc. 

Good to go.