Incorrect Magento admin grid count and paging when using group by in Collection
0I had this issue and i have got it working by implementing custom getSize() function in the collection i am using
public function getSize() { $select = clone $this->getSelect(); $select->reset(); $select = $this->getConnection()->fetchOne('SELECT COUNT(*) FROM Table GROUP BY FIELD'); // or you can use select count(distinct field) from table return $select; }
and to achieve Grid storing i have override
protected function _setCollectionOrder($column) { $collection = $this->getCollection(); if ($collection) { $columnIndex = $column->getFilterIndex() ? $column->getFilterIndex() : $column->getIndex(); $collection->getSelect()->order(array($columnIndex.' '.$column->getDir())); } return $this;
}
and Set filter_index of the columns TO
in _prepareColumns() function 'filter_index' => 'SUM(tablename.field)'
and you can use Callback function on filters for the columns
Cannot save shipment. – Magento Error
2Once before We had attribute set deleted so we lost all the products related to this attribute set!! It was quit 40k Products. So we had to roll back the database to yesterday DB Backup and re-import Customers and Orders !!
I will describe in details import/export customers and orders next post.
Now after the import and export we had this Error Cannot save shipment. when we try to create shipment for the Orders.
So after deep digging and debugging into the problem i found that the reason is the increment_id for the generated shipment object is duplicated while it should be unique in the DB .so i have looked at the DB and found that there is table in the database that store last increment_id for orders/invoices/shipments/credit memos in magento which is `eav_entity_store`
`entity_type_id` = 8 // For Shipment increment id
`entity_type_id` = 5 // For Orders increment id
`entity_type_id` = 6 // For Invoices increment id
`entity_type_id` = 7 // For Credit Memo increment id
So I just adjusted the Increment ID of the shipment in the table to be last shipment id i have after export the data
and it works fine !!
Resize Images on the FLY !
6Hi,
I was trying to make custom Media gallery page in Drupal with custom module
I made a content type that contain the image field with other fields i want Then i was trying to resize this images to fit my needs, I went through some modules but was useless.
till i found out how to resize images on the fly on drupal !
Follow This steps :-
Go to Admin => Configuration => Image styles
Then add Custom styles depending on what w=you want ( scale / resize …. ) The save.
And in you module function
$image_thumb = image_style_url('customstyle1', $item -> field_image['und']['0']['uri']); $image_big_thumb = image_style_url('customstyle2', $item -> field_image['und']['0']['uri']);
Then you can use it in your html
Custom Multi-Language 404 Page Drupal 7
0Hi,
I wanted to make custom template for my 404 and even its changeable from Drupal admin so at any time you can change it
I have created content type and i called it 404
then i used preprocess+page hook to my theme template.php file
function mymoudle_preprocess_page(&$variables, $hook) { $language = $GLOBALS['language']->language; if(!drupal_is_front_page()) { $status = drupal_get_http_header("status"); if($status != '404 Not Found' && $variables['node']->type !='') { if($language!=$variables['node']->language || $variables['node']->type=='404_pages') { drupal_goto('page-not-found'); } } } }
Mac OS x Lion
4Hello,
I have recently moved all my development environment to Mac OS x Lion ( MC 723 )
and i was looking for a lot of alternatives to my windows development stack and IDE ( PHP Designer )
I have tried Zend Server CE but i had a problem getting APC works because different arch x64 !
I have tried MAMP Pro but it sucks as well, i didn’t find it interesting
Finally i have tried using port ! and i really liked it ! and i found it really cool and worth trying ! with good support of almost all and last versions of extensions !
now i have my LAMP Stack UP with phpmyadmin as well !
then when i was looking for a good IDE, I have tried Zend Studio and i find it cool but its bit laggy with huge delay in building functions indexes from files !
I have tried Komodo IDE, it was better than Zend Studio but i didn’t find comfortable in some code completion and highlighting etc ..
Actually i was looking for Replacement for PHP Designer which i consider the most cool IDE in windows !
I have check other in IDE’s but forget all of THEM ! I found PHP Storm ! which beats all the IDE’s i have used till now !
Its Fast, Too much powerful, with very wide range of almost all feature you can ever NEED !!!
I like it and i’m using it in my development stack now !
For UML Diagrams and MySQL Schema tools i found mysql workbench works out of the box ! and i didn’t need for replacements
- The most thing that annoyed me is that I can’t create new files in MAC ! which is really stupid ! i’m using NewDoc now with customized package files to not show it in the Dockbar when launched
- Another things is the Finder !!! no Cut/Multi-Tabs/Show hidden files !!!!! it really miss alot of things !! I’m using Total Finder which i find all what i need in it.
- For SVN I’m using cornerstone which is really powerful and i like it.
I had some pain finding best things that fit my need ! Hope you find this things helpful when you start development in MAC !
Get Drupal Nodes by Node Type
3While building custom theme for Multilingual Drupal 7.x site that displaying custom news type at front page
i have wrote this function to get the nodes i want and display them in the front page
function mymodule_get_front_page_nodes() { $lang = $GLOBALS['language']->language; if($lang =='ar') { $items = mymodule_get_node_ids('event','ar'); // type = event ( machine name of the content type ) }else { $event_items = mymodule_get_node_ids('event','en'); // lang = en which is after translate the nodes } function mymodule_get_node_ids($type,$lang) { $result = db_select('node','n')->fields('n',array('nid')) ->condition('type',$type,'=') ->condition('language',$lang,'=') ->condition('status','1','=') ->orderBy('created','DESC') ->execute(); $node_list = array(); foreach ($result as $nid) { $node_list[$nid->nid] = $nid->nid; } return node_load_multiple($node_list); }
Drupal Notifcations
1Using drupal notification messages for some purposes ( form validations in custom modules )
it was really helpful to use the built in drupal notifications instead of manually writing ones !
Using menu hook in drupal to build customs menus.
function mymoudule_login() { if ($_POST) { if (validate_login($_POST['username'], $_POST['password'])) { drupal_set_message('You have successfully logged in'); drupal_goto('mymodule/success'); } else { drupal_set_message('Wrong username or password'); } } $messages = drupal_get_messages(); // notification message array() $html = $msg['status'][0]; // get the first message that we set $html .= '<form method="post"> <input name="username" type="text"><label>Username</label> <input name ="password" type="password"><label>Password</label> '; } function validate_login($user, $pass) { //put validation database here or whatever }
Managing Session Data in Drupal
4I was so confused how to to manage the session data in Drupal when i was building some modules !
I looked at the manual and some other articles around and here is what i found
- Drupal session started in bootstrap so you don’t need to start session in you module !
- You can access session data normally via superglobal session array $_SESSION
- To save data in the Session array
ymodule_function_setname($name) { $_SESSION['name'] = $name; drupal_save_session(); } mymodule_function_getname() { return $_SESSION['name']; }
- There is some other Useful function for session management in Drupal
drupal_save_session Determines whether to save session data of the current request. drupal_session_commit Commits the current session, if necessary. drupal_session_destroy_uid Ends a specific users session(s). drupal_session_initialize Initializes the session handler, starting a session if needed. drupal_session_regenerate Called when an anonymous user becomes authenticated or vice-versa. drupal_session_start Forcefully starts a session, preserving already set session data. drupal_session_started Returns whether a session has been started.
Drupal Send Mail with SMTP !
1Hello,
During building some modules for Drupal 7.x that needs to send an emails, and the mail() function is disabled its only allowed to send email via SMTP Server.
I have read drupal documentations and go through a lot of articles and posts but no hope !
I found plugin called SMTP for drupal and its working out of the box.
- Download and install the plugin.
and here is a function that show you how to send an email in drupal 7.x
function modulename_sendmail( $email = 'to_email@example.com') { $module = 'modulename'; $key = 'key'; // Random key $language = language_default(); $lang = $GLOBALS['language']->language; $params = array(); $from = 'noreplay@example.com'; $send = FALSE; $message = drupal_mail($module, $key, $email, $language, $params, $from, $send); $message['subject'] = 'Hello,This is Subject'; $message['body'] = array(); $message['body'][] = 'Greetings, Here your message body'; $system = drupal_mail_system($module, $key); $message = $system->format($message); $message['result'] = $system->mail($message); }
