Skip to content

Instantly share code, notes, and snippets.

View amacgregor's full-sized avatar
:shipit:
Working on Side Projects

Allan MacGregor amacgregor

:shipit:
Working on Side Projects
View GitHub Profile
@amacgregor
amacgregor / IndexController.php
Last active December 21, 2015 16:48
Added the new save action
<?php
...
public function saveAction()
{
if ($data = $this->getRequest()->getPost()) {
try {
$model = $this->_initModel();
@amacgregor
amacgregor / IndexController.php
Created August 25, 2013 19:56
Update actions
<?php
...
public function newAction()
{
$this->_initModel();
$this->loadLayout();
$this->renderLayout();
return $this;
}
@amacgregor
amacgregor / IndexController.php
Last active December 21, 2015 16:49
Full IndexController.php code
<?php
class Mdg_Giftregistry_IndexController extends Mage_Core_Controller_Front_Action
{
public function preDispatch()
{
parent::preDispatch();
if (!Mage::getSingleton('customer/session')->authenticate($this)) {
$this->getResponse()->setRedirect(Mage::helper('customer')->getLoginUrl());
$this->setFlag('', self::FLAG_NO_DISPATCH, true);
}
@amacgregor
amacgregor / mdg_giftregistry.xml
Created August 25, 2013 20:07
Change the layout for the new and edict actions
<?xml version="1.0"?>
<layout version="0.1.0">
...
<mdg_giftregistry_index_new>
<reference name="content">
<block name="giftregistry.new" type="core/template" template="mdg/form.phtml" as="giftregistry_new"/>
</reference>
</mdg_giftregistry_index_new>
@amacgregor
amacgregor / form.phtml
Created August 25, 2013 20:09
Create a new form template file
<?php
$helper = Mage::helper('mdg_giftregistry');
$loadedRegistry = Mage::registry('current_giftregistry')
?>
<?php if($loadedRegistry): ?>
<form action="<?php echo $this->getUrl('giftregistry/index/save/') ?>" method="post" id="form-validate">
<fieldset>
<?php echo $this->getBlockHtml('formkey')?>
<input type="hidden" name="registry_id" id="registry_id" value="<?php echo $loadedRegistry->getEntityId(); ?>"/>
<input type="hidden" name="type_id" id="type_id" value="<?php echo $loadedRegistry->getTypeId(); ?>" />
@amacgregor
amacgregor / view.phtml
Last active December 21, 2015 16:49
Updated code with error message
<?php $registry = Mage::registry('loaded_registry'); ?>
<?php if($registry->getId()): ?>
<h3><?php echo $registry->getEventName(); ?></h3>
<p><strong><?php $this->__('Event Date:') ?> <?php echo $registry->getEventDate(); ?></strong></p>
<p><strong><?php $this->__('Event Location:') ?> <?php echo $registry->getEventLocation(); ?></strong></p>
<?php else: ?>
<h3>There was an error, the requested registry does not exist.</h3>
<?php endif; ?>
delimiter ;;
drop procedure if exists build_catalog;;
create procedure build_catalog(IN categories INT, IN products INT)
begin
SET @category_count = 1;
SET @CATNAMEPREFIX = "Category ";
SET @CATURLKEYPREFIX = "cat-";
SET @CATURLPATHPREFIX = "catpath-";
SET @ROOTCATEGORY = 2;
SET @INCLUDEINMENU = 1;
@amacgregor
amacgregor / Product.php
Created December 29, 2013 01:49
Magento2 Catalog/Product class snippet
<?php
namespace Magento\Catalog\Model;
class Product extends \Magento\Catalog\Model\AbstractModel
{
...
/**
* @param \Magento\Core\Model\Context $context
* @param \Magento\Core\Model\Registry $registry
@amacgregor
amacgregor / Product.php
Created December 29, 2013 01:52
Magento1 Product class constructor
<?php
class Mage_Catalog_Model_Product extends Mage_Catalog_Model_Abstract
{
/**
* Initialize resources
*/
protected function _construct()
{
$this->_init('catalog/product');
; ahk-vim-navigation.ahk
; Written by Jongbin Jung
;
; Incorporated some script from Model_Vim.ahk
; Written by Rich Alesi
; and Modified for AHK_L by Andrej Mitrovic
; (http://www.autohotkey.com/board/topic/41206-modal-vim/)
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.