SlideShare a Scribd company logo
Migrating One of the Most
Popular eCommerce
Platforms to MongoDB
MongoDB Munich 2013, October 14th
Aron Spohr, fashion4home GmbH, Berlin
aron.spohr@fashionforhome.de
Will it blend?
What is Magento?
●
●
●
●
●
●
●

Open eCommerce platform
Serves all primary features of a Webshop
Written in PHP
Works on top of MySQL out of the box
Extensible architecture
Runs on over 180,000 sites
eBay owned since 2011
The Shopping Cart
● Quote
● Items
● Addresses

● one Model for each
● one MySQL-Table for each
Data Structure
quote_id

discount_amount

grand_total

560

100.00

299.00

561

0.00

quote

1028.40

quote_item
item_id

quote_id

product_id

qty

price

100

560

1257

1

39.90

101

560

1349

2

140.10

quote_address
address_id

quote_id

city

street

type

388

560

Munich

Hauptstr. 33a

shipping

389

560

Berlin

Zahlstrasse 12

billing

390

561

Hamburg

Geheimweg 3

shipping, billing
as a developer in
// Loading a quote from database
$quote = Mage::getModel(‘sales/quote’)->load(560);

SELECT * FROM sales_quote WHERE quote_id=560;
// Loading a filtered collection of quote items from database
$items = $quote->getItemCollection();
$items->addFieldToFilter(‘product_id’, 1257);
$items->load();

SELECT * FROM sales_quote_item WHERE
quote_id=560 AND product_id=1257;
Persistence in

Application

every Model has
● a Resource Model to load/save one record from/to DB
● a Collection Model to load multiple records from DB

Model

Resource Model
DB

Collection Model

Model

Model

Model
Resource Model basics of
function load($object, $id) {
$stmt = “SELECT * FROM “ . $this->getTableName() .
” WHERE “ . $this->getIdFieldname() . ”=$id”;
$data = $sqlAdapter->fetchRow( $stmt );
$object->setData( $data );
}
Collection Model basics of
function load() {
$stmt = “SELECT * FROM “ . $this->getTableName() .
” WHERE “ . $this->renderFilters();
foreach($sqlAdapter->fetchRows( $stmt ) as $row) {
$object = new Object();
$object->setData($data);
$this->addItem($object);
}
}
Why should we change that?
● You don’t have to
● It always depends on your application
Reasons we had:
● Have more/other scalability options
● Make it easier to work with raw data
● Be more flexible with your data schema
● Learn more about the software you are using
Let’s get started
●
●
●
●

not change the way Magento works
a very simple, self-explainable data schema
make it easy to migrate old data
not lose any existing features
Data Structure - mongoDB
{
quote_id: 560,
discount_amount: 100.00,
grand_total: 299,
item: [
{item_id: 100, product_id: 1257, qty: 1, price: 39.9},
{item_id: 101, product_id: 1349, qty: 2, price: 140.10}
],
address: [
{address_id: 388, city: ‘Munich’, street: ‘Hauptstr. 33a’, ...},
{address_id: 389, city: ‘Berlin’, street: ‘Zahlstrasse 12’, ...}
]
}
Do we still have a table?
SELECT * FROM quote_item;

db.quote.find(

{}, { ‘item’: 1 } );

● { ‘item’:[ {item_id: 100, product_id: 1257, qty: 1 },
{item_id: 101, product_id: 1349, qty: 2 } ] }
● { ‘item’:[ {item_id: 102, product_id: 4421, qty: 1 } ] }
● { ‘item’:[ {item_id: 103, product_id: 2301, qty: 1 },
{item_id: 104, product_id: 5511, qty: 1 } ] }
● ...
a Tool to simplify our work with mongoDB...
Loading a collection of things
loadDataCollection(‘/quote/item’, array());
●
●
●
●

{ item_id: 100, product_id: 1257, qty: 1 }
{ item_id: 101, product_id: 1349, qty: 2 }
{ item_id: 102, product_id: 4421, qty: 1 }
...

db.quote.find( {}, { ‘item’: 1 } );
● { ‘item’:[
● { ‘item’:[
● ...

{item_id: 100, product_id: 1257, qty: 1},
{item_id: 101, product_id: 1349, qty: 2} ] }
{item_id: 102, product_id: 4421, qty: 1} ] }
The path to our data
Name of Collection
/quote /item
Name of Array
in document
● Tells us where to find the data
● Is very similar to a table name
We rewire all Table names in

quote

/quote

quote_item

/quote/item

quote_address

/quote/address
The new Collection Model
$rows = $newAdapter->loadDataCollection(
$this->getTableName(),
$this->renderFilters() );
foreach($rows as $row) {
$object = new Object();
$object->setData($data);
$this->addItem($object);
}
Loading a collection of things (filtered)
loadDataCollection(‘/quote/item’, array(product_id => 1257));
● { item_id: 100, product_id: 1257, qty: 1 }
● { item_id: 342, product_id: 1257, qty: 2 }
● ...

db.quote.find( { ‘item.product_id’: 1257 }, { ‘item’: 1 } );
● { ‘item’:[
● { ‘item’:[
● ...

{item_id: 100, product_id: 1257, qty: 1} ] }
{item_id: 342, product_id: 1257, qty: 2} ] }
as a developer in

// loading a filtered collection of quote items from database
$items = Mage::getModel(‘sales/quote_item’)->getCollection();
$items->addFieldToFilter(‘quote_id’, 560);
$items->addFieldToFilter(‘product_id’, 1257);
$items->load();
Loading a collection of things (filtered)
● This is not a relational database anymore
● Quote Items may not have a quote_id in our schema
loadDataCollection( ‘/quote/item’,
array( ‘quote_id’ => 560, ‘product_id’ => 1257) );
- no result
db.quote.find(
{ ‘item.quote_id’: 560, ‘item.product_id’: 1257 },
{ ‘item’: 1 } );
- no result
Loading a collection of things (filtered)
loadDataCollection( ‘/quote{quote_id:560}/item’,
array(product_id=> 1257));
● { item_id: 100, product_id: 1257, qty: 1 }

db.quote.find(

● { ‘item’:[

{‘quote_id’: 560, ‘item.product_id’: 1257},
{ ‘item’: 1 } );

{item_id: 100, product_id: 1257, qty: 1} ] }
On-the-fly Tablename completion
getTablename()

/quote{quote_id:$quote_id}/item

completePath(filters, properties)

/quote{quote_id:560}/item
as a developer in
// load a single item from db, change qty, save it
$item = Mage::getModel(‘sales/quote_item’)->load(101);
$item->setQty(2);
$item->save();
// add a product to cart
$item = Mage::getModel(‘sales/quote_item’);
$item->setQuoteId(560)->setProductId(1566)->setQty(1);
$item->save();
Loading a single record
loadData( ‘/quote{quote_id:560}/item’, ‘item_id’, 100);
findOne({ ‘quote_id’: 560, ‘item.item_id’: 100}, {‘item.$’: 1});
loadData( ‘/quote/item’, ‘item_id’, 100);
loadData( ‘/quote{quote_id:$quote_id}/item’, ‘item_id’, 100);
findOne({ ‘item.item_id’: 100}, {‘item.$’: 1});

Result for all three
{ item_id: 100, product_id: 1257, qty: 1 }
Saving a single record
Inserting
saveData( ‘/quote{quote_id:560}/item’,
array(‘item_id’ => 732, ‘product_id’ => 1257, ‘qty’ => 1));
db.quote.update( { quote_id: 560 }, { $push : {‘item’ =>
{ item_id: 732, product_id: 1257, qty: 1 }} });
Updating
saveData( ‘/quote/item’, array(‘item_id’ => 732, ‘qty’ => 2));
saveData( ‘/quote{quote_id:$quote_id}/item’, ...);
db.quote.update( { item.item_id: 732 },
{ $set : { item.$.qty: 2 } } );
The new resource model
function load($object, $id) {
$data = $adapter->loadData(
$this->getTablename(),
$this->getIdFieldname(),
$id);
$object->setData( $data );
}
The new resource model
function save($object) {
$id = $this->getNewId();
$data = $adapter->saveData(
$this->getTablename(),
$this->getIdFieldname(),
$id,
$object->getData());
$object->setId($id);
}
Migration of old data in

Application

create a simple application to
● load using the old resource model
● save using the new resource model

Old Resource Model
Model
New Resource Model

DB
Thanks a lot

Firefly Glow Cube

Dining Table Campagna

More Related Content

PPTX
Pegomock, a mocking framework for Go
PDF
New Query Optimizer features in MariaDB 10.3
PPT
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
PDF
Meetup Beleza na Web - Funções analíticas com SQL
DOC
Useful c programs
PDF
POC d'une architecture distribuee de calculs financiers
PDF
Stl algorithm-Basic types
PPTX
Derivadas en Contabilidad y Auditoría
Pegomock, a mocking framework for Go
New Query Optimizer features in MariaDB 10.3
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
Meetup Beleza na Web - Funções analíticas com SQL
Useful c programs
POC d'une architecture distribuee de calculs financiers
Stl algorithm-Basic types
Derivadas en Contabilidad y Auditoría

What's hot (15)

PPT
Introduction to AspectJ
PDF
Implementing string
PPT
Supstat nyc subway
PDF
Import data from csv excel file and export to xml excel file in c programming
PDF
Data Structure in C Programming Language
PPTX
4. chapter iii
PDF
Aplikasi menghitung matematika dengan c++
PPT
C questions
PPTX
3. chapter ii
DOC
Practical Class 12th (c++programs+sql queries and output)
DOCX
PDF
Visual Studio.Net - Sql Server
PDF
54602399 c-examples-51-to-108-programe-ee01083101
PPTX
Oracle SQL Functions
Introduction to AspectJ
Implementing string
Supstat nyc subway
Import data from csv excel file and export to xml excel file in c programming
Data Structure in C Programming Language
4. chapter iii
Aplikasi menghitung matematika dengan c++
C questions
3. chapter ii
Practical Class 12th (c++programs+sql queries and output)
Visual Studio.Net - Sql Server
54602399 c-examples-51-to-108-programe-ee01083101
Oracle SQL Functions
Ad

Similar to Migrating one of the most popular e commerce platforms to mongodb (20)

PPTX
MongoDB World 2018: Keynote
PDF
Distilled mongo db by Boris Trofimov
PPTX
Retail referencearchitecture productcatalog
PDF
Managing Database Indexes: A Data-Driven Approach - Amadeus Magrabi
PDF
MongoDB: Back to Basics
PPTX
Intro to MongoDB Workshop
PPTX
Super spike
PPTX
Intro to MongoDB (Extended Session)
PPTX
Meet Magento Belarus debug Pavel Novitsky (eng)
PPTX
Unify Your Selling Channels in One Product Catalog Service
PPTX
Prepare for Peak Holiday Season with MongoDB
PDF
Webinar: Delivering the Complete Customer View - Today’s Table Stakes by Infu...
PPTX
[MongoDB.local Bengaluru 2018] Keynote
PPTX
Retail Reference Architecture
PPTX
Retail Reference Architecture Part 1: Flexible, Searchable, Low-Latency Produ...
PDF
MongoDB FabLab León
PPTX
Webinar: Back to Basics: Thinking in Documents
KEY
Mongo db ecommerce
PDF
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mi...
PPTX
Chapter 6(introduction to documnet databse) no sql for mere mortals
MongoDB World 2018: Keynote
Distilled mongo db by Boris Trofimov
Retail referencearchitecture productcatalog
Managing Database Indexes: A Data-Driven Approach - Amadeus Magrabi
MongoDB: Back to Basics
Intro to MongoDB Workshop
Super spike
Intro to MongoDB (Extended Session)
Meet Magento Belarus debug Pavel Novitsky (eng)
Unify Your Selling Channels in One Product Catalog Service
Prepare for Peak Holiday Season with MongoDB
Webinar: Delivering the Complete Customer View - Today’s Table Stakes by Infu...
[MongoDB.local Bengaluru 2018] Keynote
Retail Reference Architecture
Retail Reference Architecture Part 1: Flexible, Searchable, Low-Latency Produ...
MongoDB FabLab León
Webinar: Back to Basics: Thinking in Documents
Mongo db ecommerce
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mi...
Chapter 6(introduction to documnet databse) no sql for mere mortals
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Diabetes mellitus diagnosis method based random forest with bat algorithm
sap open course for s4hana steps from ECC to s4
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The AUB Centre for AI in Media Proposal.docx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Network Security Unit 5.pdf for BCA BBA.
Understanding_Digital_Forensics_Presentation.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Electronic commerce courselecture one. Pdf
MYSQL Presentation for SQL database connectivity
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

Migrating one of the most popular e commerce platforms to mongodb

  • 1. Migrating One of the Most Popular eCommerce Platforms to MongoDB MongoDB Munich 2013, October 14th Aron Spohr, fashion4home GmbH, Berlin aron.spohr@fashionforhome.de
  • 3. What is Magento? ● ● ● ● ● ● ● Open eCommerce platform Serves all primary features of a Webshop Written in PHP Works on top of MySQL out of the box Extensible architecture Runs on over 180,000 sites eBay owned since 2011
  • 4. The Shopping Cart ● Quote ● Items ● Addresses ● one Model for each ● one MySQL-Table for each
  • 6. as a developer in // Loading a quote from database $quote = Mage::getModel(‘sales/quote’)->load(560); SELECT * FROM sales_quote WHERE quote_id=560; // Loading a filtered collection of quote items from database $items = $quote->getItemCollection(); $items->addFieldToFilter(‘product_id’, 1257); $items->load(); SELECT * FROM sales_quote_item WHERE quote_id=560 AND product_id=1257;
  • 7. Persistence in Application every Model has ● a Resource Model to load/save one record from/to DB ● a Collection Model to load multiple records from DB Model Resource Model DB Collection Model Model Model Model
  • 8. Resource Model basics of function load($object, $id) { $stmt = “SELECT * FROM “ . $this->getTableName() . ” WHERE “ . $this->getIdFieldname() . ”=$id”; $data = $sqlAdapter->fetchRow( $stmt ); $object->setData( $data ); }
  • 9. Collection Model basics of function load() { $stmt = “SELECT * FROM “ . $this->getTableName() . ” WHERE “ . $this->renderFilters(); foreach($sqlAdapter->fetchRows( $stmt ) as $row) { $object = new Object(); $object->setData($data); $this->addItem($object); } }
  • 10. Why should we change that? ● You don’t have to ● It always depends on your application Reasons we had: ● Have more/other scalability options ● Make it easier to work with raw data ● Be more flexible with your data schema ● Learn more about the software you are using
  • 11. Let’s get started ● ● ● ● not change the way Magento works a very simple, self-explainable data schema make it easy to migrate old data not lose any existing features
  • 12. Data Structure - mongoDB { quote_id: 560, discount_amount: 100.00, grand_total: 299, item: [ {item_id: 100, product_id: 1257, qty: 1, price: 39.9}, {item_id: 101, product_id: 1349, qty: 2, price: 140.10} ], address: [ {address_id: 388, city: ‘Munich’, street: ‘Hauptstr. 33a’, ...}, {address_id: 389, city: ‘Berlin’, street: ‘Zahlstrasse 12’, ...} ] }
  • 13. Do we still have a table? SELECT * FROM quote_item; db.quote.find( {}, { ‘item’: 1 } ); ● { ‘item’:[ {item_id: 100, product_id: 1257, qty: 1 }, {item_id: 101, product_id: 1349, qty: 2 } ] } ● { ‘item’:[ {item_id: 102, product_id: 4421, qty: 1 } ] } ● { ‘item’:[ {item_id: 103, product_id: 2301, qty: 1 }, {item_id: 104, product_id: 5511, qty: 1 } ] } ● ...
  • 14. a Tool to simplify our work with mongoDB...
  • 15. Loading a collection of things loadDataCollection(‘/quote/item’, array()); ● ● ● ● { item_id: 100, product_id: 1257, qty: 1 } { item_id: 101, product_id: 1349, qty: 2 } { item_id: 102, product_id: 4421, qty: 1 } ... db.quote.find( {}, { ‘item’: 1 } ); ● { ‘item’:[ ● { ‘item’:[ ● ... {item_id: 100, product_id: 1257, qty: 1}, {item_id: 101, product_id: 1349, qty: 2} ] } {item_id: 102, product_id: 4421, qty: 1} ] }
  • 16. The path to our data Name of Collection /quote /item Name of Array in document ● Tells us where to find the data ● Is very similar to a table name
  • 17. We rewire all Table names in quote /quote quote_item /quote/item quote_address /quote/address
  • 18. The new Collection Model $rows = $newAdapter->loadDataCollection( $this->getTableName(), $this->renderFilters() ); foreach($rows as $row) { $object = new Object(); $object->setData($data); $this->addItem($object); }
  • 19. Loading a collection of things (filtered) loadDataCollection(‘/quote/item’, array(product_id => 1257)); ● { item_id: 100, product_id: 1257, qty: 1 } ● { item_id: 342, product_id: 1257, qty: 2 } ● ... db.quote.find( { ‘item.product_id’: 1257 }, { ‘item’: 1 } ); ● { ‘item’:[ ● { ‘item’:[ ● ... {item_id: 100, product_id: 1257, qty: 1} ] } {item_id: 342, product_id: 1257, qty: 2} ] }
  • 20. as a developer in // loading a filtered collection of quote items from database $items = Mage::getModel(‘sales/quote_item’)->getCollection(); $items->addFieldToFilter(‘quote_id’, 560); $items->addFieldToFilter(‘product_id’, 1257); $items->load();
  • 21. Loading a collection of things (filtered) ● This is not a relational database anymore ● Quote Items may not have a quote_id in our schema loadDataCollection( ‘/quote/item’, array( ‘quote_id’ => 560, ‘product_id’ => 1257) ); - no result db.quote.find( { ‘item.quote_id’: 560, ‘item.product_id’: 1257 }, { ‘item’: 1 } ); - no result
  • 22. Loading a collection of things (filtered) loadDataCollection( ‘/quote{quote_id:560}/item’, array(product_id=> 1257)); ● { item_id: 100, product_id: 1257, qty: 1 } db.quote.find( ● { ‘item’:[ {‘quote_id’: 560, ‘item.product_id’: 1257}, { ‘item’: 1 } ); {item_id: 100, product_id: 1257, qty: 1} ] }
  • 24. as a developer in // load a single item from db, change qty, save it $item = Mage::getModel(‘sales/quote_item’)->load(101); $item->setQty(2); $item->save(); // add a product to cart $item = Mage::getModel(‘sales/quote_item’); $item->setQuoteId(560)->setProductId(1566)->setQty(1); $item->save();
  • 25. Loading a single record loadData( ‘/quote{quote_id:560}/item’, ‘item_id’, 100); findOne({ ‘quote_id’: 560, ‘item.item_id’: 100}, {‘item.$’: 1}); loadData( ‘/quote/item’, ‘item_id’, 100); loadData( ‘/quote{quote_id:$quote_id}/item’, ‘item_id’, 100); findOne({ ‘item.item_id’: 100}, {‘item.$’: 1}); Result for all three { item_id: 100, product_id: 1257, qty: 1 }
  • 26. Saving a single record Inserting saveData( ‘/quote{quote_id:560}/item’, array(‘item_id’ => 732, ‘product_id’ => 1257, ‘qty’ => 1)); db.quote.update( { quote_id: 560 }, { $push : {‘item’ => { item_id: 732, product_id: 1257, qty: 1 }} }); Updating saveData( ‘/quote/item’, array(‘item_id’ => 732, ‘qty’ => 2)); saveData( ‘/quote{quote_id:$quote_id}/item’, ...); db.quote.update( { item.item_id: 732 }, { $set : { item.$.qty: 2 } } );
  • 27. The new resource model function load($object, $id) { $data = $adapter->loadData( $this->getTablename(), $this->getIdFieldname(), $id); $object->setData( $data ); }
  • 28. The new resource model function save($object) { $id = $this->getNewId(); $data = $adapter->saveData( $this->getTablename(), $this->getIdFieldname(), $id, $object->getData()); $object->setId($id); }
  • 29. Migration of old data in Application create a simple application to ● load using the old resource model ● save using the new resource model Old Resource Model Model New Resource Model DB
  • 30. Thanks a lot Firefly Glow Cube Dining Table Campagna