Sometimes it is good to store form data in session – for example when working with filters, when you want to save last filters state when user gets back to page. But if your form has Entity type in choice field, you will see error like:
“Entity of type XXX passed to the choice field must be managed. Maybe you forget to persist it in the entity manager?”
How to deal with this? Read below.Continue reading
Category: PHP
How to install pcntl PHP extension in Mamp Pro on MacOS Catalina?
Ever wanted to install pnctl extension for Mamp PRO on Catalina in 16 easy steps? If yes, read below.Continue reading
Symfony: How to execute raw SQL which returns objects inside Form
Ever wanted to fetch your entities using complex query from inside you form class? Check out below.Continue reading
Expected argument of type “string”, “NULL” given when using form in Symfony 4.1
Expected argument of type “string”, “NULL” given is very common question and seems to not be handled since Symfony 2
How to enable php-intl extension for php 7.1 using XAMPP on MacOS High Sierra
This may seem trivial, but in fact about 2 months ago some clever guys made changes in brew repository, so doing just:
brew install php71-intl
will show you error with message that such recipe doesn’t exists. Also XAMPP comes without intl extension so is there any working solution which does not require full and manual php compilation?
Fortunately, there is. There is temporary fix in another brew repo, so all you have to do is:
brew tap kyslik/homebrew-php
brew install kyslik/php/php71-intl
And this works. Really. Enjoy.
How to find Woocommerce products out of stock with stock greater then zero?
Sometimes, especially if you are using custom plugins to import stock data, you may find products with some stock value (greater then 0) but with stock flag set to “out of stock”. How to find them? Using WP_Query of course:
$args = array( 'post_type' => 'product_variation', 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => '_stock_status', 'value' => 'outofstock', ), array( 'key' => '_stock', 'value' => '0', 'compare' => '>', 'type' => 'NUMERIC' ), ), ); $products = new WP_Query($args);
Notice ‘post_type’ => ‘product_variation’ – if you are not using variations, just change it to ‘product’.
How to make Woocommerce pages work with Polylang?
This can be really frustrating, you wanted your woocommerce shop running multilingual, but from cart page “Checkout” button leads to default language version? Solution is very simple, but not elegant – so far did not found another solution. First step is to create all woocommerce pages in every language you need, this is very simple but can take some time. Then, in your child theme (remember not to make any modifications to theme you are using!), in functions.php add such code:
function get_woocommerce_checkout_polylang() { return pll_get_post(get_option('woocommerce_checkout_page_id' ) ); } add_filter('woocommerce_get_checkout_page_id', "get_woocommerce_checkout_polylang"); function get_woocommerce_shop_polylang() { return pll_get_post(get_option('woocommerce_shop_page_id' ) ); } add_filter('woocommerce_get_shop_page_id', "get_woocommerce_shop_polylang"); function get_woocommerce_cart_polylang() { return pll_get_post(get_option('woocommerce_cart_page_id' ) ); } add_filter('woocommerce_cart_page_id', "get_woocommerce_cart_polylang"); function get_woocommerce_pay_polylang() { return pll_get_post(get_option('woocommerce_pay_page_id' ) ); } add_filter('woocommerce_pay_page_id', "get_woocommerce_pay_polylang"); function get_woocommerce_thanks_polylang() { return pll_get_post(get_option('woocommerce_thanks_page_id' ) ); } add_filter('woocommerce_thanks_page_id', "get_woocommerce_thanks_polylang"); function get_woocommerce_myaccount_polylang() { return pll_get_post(get_option('woocommerce_myaccount_page_id' ) ); } add_filter('woocommerce_myaccount_page_id', "get_woocommerce_myaccount_polylang"); function get_woocommerce_edit_address_polylang() { return pll_get_post(get_option('woocommerce_edit_address_page_id' ) ); } add_filter('woocommerce_edit_address_page_id', "get_woocommerce_edit_address_polylang"); function get_woocommerce_view_order_polylang() { return pll_get_post(get_option('woocommerce_view_order_page_id' ) ); } add_filter('woocommerce_view_order_page_id', "get_woocommerce_view_order_polylang"); function get_woocommerce_terms_polylang() { return pll_get_post(get_option('woocommerce_terms_page_id' ) ); } add_filter('woocommerce_terms_page_id', "get_woocommerce_terms_polylang");
All those functions are using same pll_get_post from Polylang plugin, to translate your default page ID you set in Woocommerce/Settings/Checkout/Checkout Pages to their translated version. Hope you will find it useful.
How to manually generate bootstrap.php.cache using Symfony 2?
Well, the easiest way is to use
composer.phar update
but if you don’t want to update all bundles and waste an hour of your time, you can use:
php vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle\Resources\bin\build_bootstrap.php <app>
where <app> is placeholder for you app dir, like “app/frontend” or “app/backend”
in case you don’t have build_bootstrap.php on path above (it works for Symfony 2.7.x) just search for it inside vendor\sensio\distribution-bundle\Sensio\Bundle\DistributionBundle
Quick tip: How to add WSSE Security headers in SoapUI?
Since this information is not easy to find, I want to share it with you. Valid WSSE security header should look like this:
<soapenv:Header> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1"> <wsse:UsernameToken> <wsse:Username>yourusername</wsse:Username> <wsse:Password>yourpassword</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header>
this way you can execute request requiring this header.
How to fix WooCommerce 404 error on product page
This can be frustrating when you are new to wordpres and/or woocommerce. You just created your first product, and got 404 when trying to see it. Fortunately solution is quite simple. In backend panel go to “Settings”, then “Permalinks”. In “Common settings” section make sure “Post Name” is selected, if not, choose it – it will look like “http://newbl.blastar.biz/sample-post/”. Then look below, in “Product permalink base” section choose “Shop base” – it will look like “http://newbl.blastar.biz/shop/sample-product/”. Click “Save CHanges” and below you should see new box with .htaccess settings like:
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Just copy it and paste to your .htaccess. All links should work now!