Skip to content

Instantly share code, notes, and snippets.

@Alexander-Pop
Alexander-Pop / magento-get-base-urls.php
Created June 11, 2019 15:09
magento - Get base Url and system folders
<?php
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
// http://mysitedomain.com/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN);
// http://mysitedomain.com/skin/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
// http://mysitedomain.com/media/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
// http://mysitedomain.com/index.php/
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
@Alexander-Pop
Alexander-Pop / magento-access-from-other-app.php
Created June 11, 2019 15:14
Magento - access from other app
include the Mage.php(app/Mage.php) file residing in app folder of magento to our file which resides outside of magento folder .
<?php
// Include Magento application
require_once ( "/var/www/your-magento-directory/app/Mage.php" );
umask(0);
// Initialize Magento
Mage::app("default");
@Alexander-Pop
Alexander-Pop / wordpress-divi-sidebar.php
Last active June 28, 2019 13:53
Worpress - DIVI - Regular Sidebar on Page Builder Pages #wp #wp_theme
Show settings in the Page Layout Meta Box
<?php
//therme functions.php
add_action( 'admin_head', 'my_custom_admin_styles' );
function my_custom_admin_styles() {
echo '<style>.et_pb_page_layout_settings {display: block!important;}</style>';
};
// divi subtheme page.php after the get_header() right
@Alexander-Pop
Alexander-Pop / magento-track-events.php
Last active June 28, 2019 13:52
Magento 1 - track what events were despatched #magento #event
app\code\core\Mage\Core\Model\App.php
<?php
public function dispatchEvent($eventName, $args){
$eventName = strtolower($eventName);
foreach ($this->_events as $area=>$events) {
/* add this */
//Mage::log($eventName, null, 'events.log');
//Mage::log("test", null, 'events.log');
@Alexander-Pop
Alexander-Pop / php-how-session-works.txt
Last active June 28, 2019 13:51
How PHP session works #php #server #cookie
Firstly PHP creates a unique identifier number (a random string of 32 hexadecimal number, e.g 3c7foj34c3jj973hjkop2fc937e3443) for an individual session.
PHPSESSID cookie passes that unique identification number to users’ browser to save that number.
A new file is created on the server with the same name of unique identification number with sess_ prefix (ie sess_3c7foj34c3jj973hjkop2fc937e3443.)
The browser sends that cookie to the server with each request.
If PHP gets that unique identification number from PHPSESSID cookie (on each request), then PHP searches in the temporary directory and compares that number to the file name. If both are the same, then it retrieves the existing session, otherwise it creates a new session for that user.
@Alexander-Pop
Alexander-Pop / php-mamp.txt
Last active September 5, 2019 14:57
[PHP - use MAMP version] #cl #terminal #server #php #mamp
We need to be sure that PHP modules ext-mcrypt and ext-intl are loaded. PHP 7 that comes with MAMP already has them, we just need to be sure the OS uses the MAMP version.
Check the location of PHP :
which php
If the output is /usr/bin/php it means the default OSX PHP version is loaded and we need to change it.
Edit .bash_profile:
sudo nano ~/.bash_profile
or
sub ~/.bash_profile
@Alexander-Pop
Alexander-Pop / magento-quote.txt
Last active July 3, 2019 13:34
[Magento Quote] #magento
The quote is created when you call Mage::getSingleton("checkout/session")->getQuote(). Check how the method Mage_Checkout_Model_Session::getQuote works. If there is a quote for the specified customer it returns it. If not, it creates one and returns it
is_active field is used in the following cases:
is_active is always 1 for cart/quote created by web user
is_active is always 0 for cart/quote created from admin
To load quote by Customer Id, is_active = 1 is taken into account
When quote is converted to order, is_active becomes 0
To restore the quote which is cleared by payment errors etc during checkout., make is_active = 1
When you create a quote via API, is_active is always 0
@Alexander-Pop
Alexander-Pop / magento-quote-order.txt
Created July 3, 2019 13:35
Magento - Quote/order product item attribute based on user input #magento
Magento provides a capability for adding options that aren't product attributes or product custom options. They are set on the product and quote items with the option code additional_options.
There are two steps you need to take, each can be handled via an event observer. If you want the additional options to carry through reordering, you will need also observe a third event.
Add options to quote item
The first step is to add the event observer to set the additional options on the loaded product before it is added to the cart. One option is to use the catalog_product_load_after event.
<catalog_product_load_after>
<observers>
<extra_options>
@Alexander-Pop
Alexander-Pop / use-magento-session-outside-of-magento.php
Last active July 3, 2019 13:56
Magento - use magento session outside of magento #magento #session
<?php
echo getcwd();
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::app()->loadArea('frontend');
// access the magento session outside
$customerSession = Mage::getModel('customer/session');
print_r($customerSession);
@Alexander-Pop
Alexander-Pop / mamp-php-version-edit-ini.txt
Last active September 5, 2019 15:00
[MAMP PHP Version] change memory #php #mamp #cl
# SEE version
php -v
# See What loaded
which php
# See settings (memory_limit)
php -i | grep memory_limit
or
php -r "echo ini_get('memory_limit').PHP_EOL;"