Skip to content

Instantly share code, notes, and snippets.

@hosts(["mckenzie.servers.ljworld.com"])
def pull_db(db_name, user_db_name=None):
if db_name is None:
exit("You must provide a database name")
# add username to db_name
if user_db_name is None:
user_db_name = '%s_%s' % (env.user, db_name)
@ecogswell
ecogswell / gist:2361689
Created April 11, 2012 19:27
marketplace test settings
from marketplace.test.settings import *
DEBUG=True
DATABASES['default']['HOST'] = 'localhost'
DATABASES['default']['NAME'] = 'marketplacedemo'
DATABASES['default']['USER'] = 'postgres'
code_path = os.path.expanduser('~/code')
@ecogswell
ecogswell / gist:2369464
Created April 12, 2012 17:35
affiliations fixes
diff --git a/marketplace/affiliations/admin.py b/marketplace/affiliations/admin.py
index 87f3e01..f5ad40e 100644
--- a/marketplace/affiliations/admin.py
+++ b/marketplace/affiliations/admin.py
@@ -10,6 +10,7 @@ class AffiliationAdmin(BaseModelAdmin):
search_fields = ('name',)
prepopulated_fields = {'slug': ('name',)}
list_filter = ('type', 'featured',)
+ raw_id_fields = ('created_by',)
@ecogswell
ecogswell / gist:3352027
Created August 14, 2012 19:33
Magento Certification Study Links
Get Ready for Magento Certified Developer Exam. Magento Codepool
http://blog.belvg.com/magento-certification-magento-codepool.html
Get Ready for Magento Certified Developer Exam. Magento Module Structure.
http://blog.belvg.com/magento-certification-module-structure.html
Get Ready for Magento Certified Developer Exam. The Main Magento Design Areas and More…
http://blog.belvg.com/get-ready-for-magento-certified-developer-exam-the-main-magento-design-areas-and-more.html
Get Ready for Magento Certified Developer Exam. Class Naming Conventions and Their Relationship with the Autoloader
public function getCsv()
{
$csv = '';
$this->_isExport = true;
$this->_prepareGrid();
$sql = (string)$this->getCollection()->getSelect()->__toString();
$db = Mage::getResourceSingleton('core/resource')->getReadConnection();
$result = $db->query($sql);
Dealing With Large Collections in Magento
- Collections are a good thing
- make deailing with multiple data structure types easy: Standard and EAV
- Lazy loading keep database traffic to a minimum
- Collections have some shortcomings
- When dealing with a large number of customers, getting EAV data can be difficult
The situation:
SELECT
`main_table`.`customer_id`,
`main_table`.`customer_firstname` AS `firstname`,
`main_table`.`customer_lastname` AS `lastname`,
`distributor`.`name` AS `distributor_name`,
(select COUNT(distinct MONTH(created_at)) from sales_flat_order where customer_id=main_table.customer_id and created_at between '0000-00-00' and NOW()) AS `order_months_count`,
(select sum(total_qty_ordered) from sales_flat_order where customer_id=main_table.customer_id and created_at between '0000-00-00' and NOW()) AS `total_qty_ordered`,
(select sum(base_grand_total) from sales_flat_order where customer_id=main_table.customer_id and created_at between '0000-00-00' and NOW()) AS `total_grand_total`,
sum(MONTH(main_table.created_at) = 1) AS `Jan_count`,
<?php
protected function _prepareCollection()
{
$filters = $this->getRequest()->getParams();
$start_date = (isset($filters['date_from'])) ? date("'Y-m-d'", strtotime($filters['date_from'])) : "'0000-00-00'";
$end_date = (isset($filters['date_to'])) ? date("'Y-m-d'", strtotime($filters['date_to'])) : 'NOW()';
$collection = Mage::getModel("sales/order")->getCollection();
$resource = Mage::getSingleton('core/resource');
$distributorTable = $resource->getTableName('PurinaPro_Groups/Distributor');
@ecogswell
ecogswell / Imagine_2013_resources
Created April 16, 2013 19:18
A short list of presentations from Magento Imagone 2013
All breakout session presentations:
http://www.imagineecommerce.com/2013breakouts/
Magento: Best practices for hosting
http://www.nexcess.net/magento-best-practices-whitepaper
http://info.magento.com/rs/magentocommerce/images/HostandBoastBestPracticesForMagentoHosting.pdf
Data Isolation and Merchandizing in a Single Magento Instance
http://info.magento.com/rs/magentocommerce/images/DataIsolationandMerchandizinginaSingleMagentoInstance.pdf