Skip to content

Instantly share code, notes, and snippets.

@sunnycyk
Last active June 6, 2017 00:37
Show Gist options
  • Save sunnycyk/9064bb2bef6a93d4ff89 to your computer and use it in GitHub Desktop.
Save sunnycyk/9064bb2bef6a93d4ff89 to your computer and use it in GitHub Desktop.
Magento
$connection = $installer->getConnection();
$connection->addKey(
TABLE_NAME,
'IDX_ENTITY',
array('entity_type_id', 'attribute_id', 'store_id', 'entity_id'),
UNIQUE
);
<events>
<controller_front_send_response_before>
<observers>
<custom_module>
<type>singleton</type>
<class>custome_module/observer</class>
<method>customRedirect</method>
</custom_module>
</observers>
</controller_front_send_response_before>
</events>
// Create Order
$order = Mage::getModel('sales/order')
->setIncrementId($reservedOrderId)
->setStoreId($this->_storeId)
->setQuoteId(0)
->setGlobalCurrencyCode($currencyCode)
->setBaseCurrencyCode($currencyCode)
->setStoreCurrencyCode($currencyCode)
->setOrderCurrencyCode($currencyCode)
->setBaseToGlobalRate(1.0) // In order to show it in Dashboard, this must set to 1.0
->setBaseToOrderRate(1.0);
// Shipping
$order->setShippingAddress($shippingAddress)
->setShippingMethod('flatrate_flatrate')
->setShippingAmount(5)
->setBaseShippingAmount(5)
->setShippingDescription('flatrate'); // This must be set to show 'flatrate in order
<?php
class Custom_Module_Model_Observer {
public function customRedirect() {
$url = Mage::helper('core/url')->getCurrentUrl();
$url = Mage::getSingleton('core/url')->parseUrl($url);
$path = $url->getPath();
$action = Mage::app()->getRequest()->getActionName();
$pattern = '/[.*]?\/custommodule\/index\/[.*]?|[.*]?\/admin[$.*]?/';
if (!(preg_match($pattern, $path, $matches) == 1) || $action == 'noRoute') {
Mage::app()->getFrontController()->getResponse()->clearHeaders()->setRedirect(Mage::getUrl("custommodule/index/index"));
// SSL
// Mage::app()->getFrontController()->getResponse()->clearHeaders()->setRedirect(Mage::getUrl("customemodule/index/index", array('_forced_secure' => true)));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment