Thursday, December 18, 2014

Autoincrement MySQL increase to allow clone to insert new without collisions (for a time)

-- this will allow you to update a schema(s) to approx double the max autoincrement value of the data_type (int, smallint, mediumint...)  works well for dev servers that are replicating live data and you want to add data.
-- select the awesomeness of information schema

use information_schema;
-- create alter table statements into an outfile
SELECT concat ("ALTER TABLE `",table_schema,"`.`",table_name,"` AUTO_INCREMENT=",IF(DATA_TYPE='smallint',15000,IF(DATA_TYPE='tinyint',64,IF(DATA_TYPE='mediumint',4000000,IF(DATA_TYPE='int',1000000000,99999999999999)))),";")
FROM `COLUMNS` WHERE extra LIKE '%auto_increment%' and table_schema IN ('schema name...')
INTO OUTFILE '/tmp/auto.sql';
-- source the outfile
source /tmp/auto.sql;

Magento Cart: show selected option value information form Custom Options selection

I wanted to get a custom "front_image_path" from the customoptions that I have implemented with MageWorx. This way I can have a shirt with multiple image options to select from for color and that will show in cart. So this code goes in the "app/design/frontend/default/default/template/checkout/cart/item/default.phtml" to modify the frontimage.
    // this is for non-customizable products
    $_options = $_product->getOptions();
    // if option enabled = no && hasOptions = 0
    if (!$_options) $optionsArr = $this->getProduct()->getProductOptionsCollection();

    /** @var MageWorx_CustomOptions_Helper_Data $helper */
    $helper = Mage::helper('customoptions');
    foreach ($_options as $_option) {
        /** @var MageWorx_CustomOptions_Model_Catalog_Product_Option $_option */
            // this option id
            $option_id = $_option->getId();
            // cart item option info
            $item_option = $_item->getOptionByCode('option_' . $option_id);

            foreach ($_option->getValues() as $_value) {
                /** @var Mage_Catalog_Model_Product_Option_Value $_value */
                $value_type = $_value->getOptionTypeId();
                if($item_option && $value_type == $item_option['value']){
                    $frontImgArr = $helper->getColorImgHtml($_value->getFrontImagePath(), $option_id, $value_type,true,true,'front');
                    $frontimage = $frontImgArr['url'];
        $frontimage = $this->getProductThumbnail();

Monday, December 8, 2014

Magento force secure urls (https) on all frontend pages.

this works in Mageno 1.9.1
use your app/etc/config.xml file
<?xml version="1.0"?>

If user is using https, this should force all urls to rewrite (created as) to https.