Is there a Magento function to get the value of "id" from this url:
http://domain.com/path/action/id/123
http://domain.com/path/action/id/123
$id = $this->getRequest()->getParam('id', 0);
Shopify, Shopify Apps, Magento, WordPress, Codeigniter, Joomla, Big Commerce | PHP
$id = $this->getRequest()->getParam('id', 0);
app/design/adminhtml/default/default/template/sales/order/shipment/create/tracking.phtml
app/design/adminhtml/default/default/template/sales/order/invoice/create/tracking.phtml
<select name="tracking[__index__][carrier_code]" id="trackingC__index__" class="select carrier" style="width:110px;" disabled="disabled">
<?php foreach ($this->getCarriers() as $_code=>$_name): ?>
<option value="<?php echo $_code ?>"><?php echo $this->escapeHtml($_name) ?></option>
<?php endforeach; ?>
</select>
<select name="tracking[__index__][carrier_code]" id="trackingC__index__" class="select carrier" style="width:110px;" disabled="disabled">
<?php foreach ($this->getCarriers() as $_code=>$_name): ?>
<option <?php if ($_code=="ups"): ?>selected<?php endif; ?> value="<?php echo $_code ?>"><?php echo $this->escapeHtml($_name) ?></option>
<?php endforeach; ?>
</select>
<models>
...
...
<kanasagra_jaydip_resource>
...
...
<printsignsize>
<table>name of your table</table>
</printsignsize>
</kanasagra_jaydip_resource>
</models>
<?php
class Kanasagra_Jaydip_Model_Printsignsize extends Mage_Core_Model_Abstract
{
const ENTITY = 'kanasagra_jaydip_printsignsize';
const CACHE_TAG = 'kanasagra_jaydip_printsignsize';
protected $_eventPrefix = 'kanasagra_jaydip_printsignsize';
protected $_eventObject = 'printsignsize';
public function _construct()
{
parent::_construct();
$this->_init('kanasagra_jaydip/printsignsize');
}
protected function _beforeSave()
{
parent::_beforeSave();
$now = Mage::getSingleton('core/date')->gmtDate();
if ($this->isObjectNew()) {
$this->setCreatedAt($now);
}
$this->setUpdatedAt($now);
return $this;
}
public function getPrintsignUrl()
{
return Mage::getUrl('kanasagra_jaydip/printsignsize/view', array('id'=>$this->getId()));
}
protected function _afterSave()
{
return parent::_afterSave();
}
public function getDefaultValues()
{
$values = array();
$values['status'] = 1;
return $values;
}
}
<?php
class Kanasagra_Jaydip_Model_Resource_Printsignsize extends Mage_Core_Model_Resource_Db_Abstract
{
public function _construct()
{
$this->_init('kanasagra_jaydip/printsignsize', 'entity_id');
}
public function lookupStoreIds($printsignId)
{
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getTable('kanasagra_jaydip/printsignsize_store'), 'store_id')
->where('printsignsize_id = ?', (int)$printsignId);
return $adapter->fetchCol($select);
}
protected function _afterLoad(Mage_Core_Model_Abstract $object)
{
if ($object->getId()) {
$stores = $this->lookupStoreIds($object->getId());
$object->setData('store_id', $stores);
}
return parent::_afterLoad($object);
}
protected function _getLoadSelect($field, $value, $object)
{
$select = parent::_getLoadSelect($field, $value, $object);
if ($object->getStoreId()) {
$storeIds = array(Mage_Core_Model_App::ADMIN_STORE_ID, (int)$object->getStoreId());
$select->join(
array('signprint_printsignsize_store' => $this->getTable('kanasagra_jaydip/printsignsize_store')),
$this->getMainTable() . '.entity_id = signprint_printsignsize_store.printsignsize_id',
array()
)
->where('signprint_printsignsize_store.store_id IN (?)', $storeIds)
->order('signprint_printsignsize_store.store_id DESC')
->limit(1);
}
return $select;
}
protected function _afterSave(Mage_Core_Model_Abstract $object)
{
$oldStores = $this->lookupStoreIds($object->getId());
$newStores = (array)$object->getStores();
if (empty($newStores)) {
$newStores = (array)$object->getStoreId();
}
$table = $this->getTable('kanasagra_jaydip/printsignsize_store');
$insert = array_diff($newStores, $oldStores);
$delete = array_diff($oldStores, $newStores);
if ($delete) {
$where = array(
'printsignsize_id = ?' => (int) $object->getId(),
'store_id IN (?)' => $delete
);
$this->_getWriteAdapter()->delete($table, $where);
}
if ($insert) {
$data = array();
foreach ($insert as $storeId) {
$data[] = array(
'printsignsize_id' => (int) $object->getId(),
'store_id' => (int) $storeId
);
}
$this->_getWriteAdapter()->insertMultiple($table, $data);
}
return parent::_afterSave($object);
}
}
<?phpStep 5 : Add following code into your Controller File
class Kanasagra_Jaydip_Model_Resource_Printsignsize_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected $_joinedFields = array();
protected function _construct()
{
parent::_construct();
$this->_init('kanasagra_jaydip/printsignsize');
$this->_map['fields']['store'] = 'store_table.store_id';
}
public function addStoreFilter($store, $withAdmin = true)
{
if (!isset($this->_joinedFields['store'])) {
if ($store instanceof Mage_Core_Model_Store) {
$store = array($store->getId());
}
if (!is_array($store)) {
$store = array($store);
}
if ($withAdmin) {
$store[] = Mage_Core_Model_App::ADMIN_STORE_ID;
}
$this->addFilter('store', array('in' => $store), 'public');
$this->_joinedFields['store'] = true;
}
return $this;
}
protected function _renderFiltersBefore()
{
if ($this->getFilter('store')) {
$this->getSelect()->join(
array('store_table' => $this->getTable('kanasagra_jaydip/printsignsize_store')),
'main_table.entity_id = store_table.printsignsize_id',
array()
)
->group('main_table.entity_id');
/*
* Allow analytic functions usage because of one field grouping
*/
$this->_useAnalyticFunction = true;
}
return parent::_renderFiltersBefore();
}
protected function _toOptionArray($valueField='entity_id', $labelField='materials', $additional=array())
{
return parent::_toOptionArray($valueField, $labelField, $additional);
}
protected function _toOptionHash($valueField='entity_id', $labelField='materials')
{
return parent::_toOptionHash($valueField, $labelField);
}
public function getSelectCountSql()
{
$countSelect = parent::getSelectCountSql();
$countSelect->reset(Zend_Db_Select::GROUP);
return $countSelect;
}
}
$printsignsize = Mage::getModel('kanasagra_jaydip/printsignsize');
$printsignsize
->setPrintsignid($printsign->getId())
->setSizename($size['sizename'])
->setSizeword($size['sizeword'])
->setSizeprice($size['sizeprice'])
->setStores($answer['votes']);
$printsignsize->save();
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {
$_SERVER['HTTPS'] = 'on';
} else {
$_SERVER['HTTPS'] = 'off';
}
class Kanasagra_Jaydip_Block_Adminhtml_{{Entity}}_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
protected function _prepareForm() {
$form = new Varien_Data_Form(array(
'id' => 'edit_form',
'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
'method' => 'post',
'enctype' => 'multipart/form-data'
)
);
$fieldset = $form->addFieldset('{{Entity}}_form', array('legend' => Mage::helper('{{Entity}}')->__('Product information')));
$fieldset->addType('file', Mage::getConfig() ->getBlockClassName('jaydip/Adminhtml_{{Entity}}_Helper_File')); $fieldset->addField('svgimage', 'file', array( 'label' => Mage::helper('jaydip')->__('Upload SVG'), 'required' => false, 'name' => 'svgimage', )); ...
...
...
}
}
<?php
class Kanasagra_Jaydip_Block_Adminhtml_{{Entity}}_Helper_File extends Varien_Data_Form_Element_Abstract{
public function __construct($data){
parent::__construct($data);
$this->setType('file');
}
public function getElementHtml(){
$html = '';
$this->addClass('input-file');
$html.= parent::getElementHtml();
if ($this->getValue()) {
$url = $this->_getUrl();
if( !preg_match("/^http\:\/\/|https\:\/\//", $url) ) {
$url = Mage::getBaseUrl('media').'photo_image/images/' . $url; //replace this with the path to the file if you upload it somewhere else
}
$html .= '<br /><img width="100px" src="'.$url.'">';
}
return $html;
}
protected function _getUrl(){
return $this->getValue();
}
}