Tuesday, July 22, 2014

Custom Variables

For multiple stores...
  • create a custom variable
  • then click on the variable to edit.
  • select a store from the drop down (Choose Store View)
  • set (Use Default Variable Values) to NO
  • change your variables
  • access them like below...
Use it like this (note the setStoreId() to get the value for the correct store view):
$value = Mage::getModel('core/variable')
    ->setStoreId(Mage::app()->getStore()->getId())
    ->loadByCode('variable_code')
    ->getValue('text');
Or to get the html value:
$value = Mage::getModel('core/variable')
    ->setStoreId(Mage::app()->getStore()->getId())
    ->loadByCode('variable_code')
    ->getValue('html');
If no html value is defined, getValue() returns the text value if you request the html value.
thanks to stackoverflow and

Thursday, July 10, 2014

Highlight textarea where you need input via jQuery...


        !function($) {
            $.fn.setCursorPosition = function(pos,end) {
                $(this).each(function(){
                    if(typeof end == 'undefined'){
                        end = pos;
                    }
                    this.focus();
                    if (this.setSelectionRange) {
                        this.setSelectionRange(pos, end);
                    } else if (this.createTextRange) {
                        var range = this.createTextRange();
                        range.collapse(true);
                        if(pos < 0) {
                            pos = $(this).val().length + pos;
                        }
                        if(end < 0) {
                            end = $(this).val().length + end;
                        }
                        range.moveEnd('character', end);
                        range.moveStart('character', pos);
                        range.select();
                    }
                });
            }
        } (jQuery);

        $('#cForm').on('submit',function(){
            var textStr = $("#body").val();
            var exists = textStr.indexOf('??????');
            if(exists > -1){
                $("#body").setCursorPosition(exists, (exists+6) );
                $(document).trigger("event.sharedErrorContent",['Please enter a thing here.',false]);
                return false;
            }
        });

Schema - To be or not to be

TO BE!

http://rustyrazorblade.com/2014/07/the-myth-of-schema-less/

I could not agree MORE with this article. All data structures have a schema of some type whether it is a strict enforceable schema, or a weak non-maintainable structure. At least with a RDBMS you can see your schema without documentation that is typically missing anyway.