Download - Magento Best Practices
![Page 1: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/1.jpg)
Magento Best Practices
Angel [email protected]
@ashiak
Olmo Gonzá[email protected]
@olmox
Mikel [email protected]
@mkruiz
Alberto [email protected]
@aGoya
www.on4u.es
![Page 2: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/2.jpg)
Why Magento?
![Page 3: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/3.jpg)
Día 1: Magento Admin
Día 2: Magento Design
Día 3: Magento Development
![Page 4: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/4.jpg)
¿Descansos?
![Page 5: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/5.jpg)
©nicmcphee at Flickr
![Page 6: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/6.jpg)
Magento AdminDía 1:
![Page 7: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/7.jpg)
http://www.on4u.es/docs/doc/ManualMagento.pdf
Manual de Magento
![Page 8: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/8.jpg)
Let's go!
![Page 9: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/9.jpg)
Checklist (I)
✔ Instalación
✔ Permisos
✔ GIT
✔ Compilación
✔ Gestión de divisas
✔ Emails transaccionales
✔ Permisos
✔ Magento Connect
✔ Caches e índices
![Page 10: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/10.jpg)
Checklist (II)
✔ Gestionar tiendas.
✔ Configuración [scope]
✔ Conf>Web: urls y usar CDN. Certificados SSL.
✔ Conf>Diseño>Encabezado-> Robots.txt
✔ Conf>Catálogo>SEO
✔ Configuración de divisas, precios (global o website)
✔ Conf->WYSIWYG
✔ Conf->Catálogo (tablas flat)
✔ Buscador y Términos de búsqueda
✔ Inventario
![Page 11: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/11.jpg)
Checklist (III)
✔ Clientes-> Scope, impuestos, asignaciones a grupos
✔ Clientes->Carrito persistente
✔ Ventas->Impuestos, FPT
✔ Checkout->Métodos de envío
✔ Checkout->Métodos de pago
✔ Avanzado->Desarrollador
✔ Estados de pedidos
✔ Conjunto de atributos
✔ Categorías
✔ Poner el CRON de Magento
![Page 12: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/12.jpg)
Recursos útiles
Guía de uso de GIT con Magento
https://www.sonassi.com/knowledge-base/our-magento-git-guide-and-work-flow/
Mejorar buscador
http://magento.stackexchange.com/questions/1137/search-type-like-full-text-or-combined
http://www.magentocommerce.com/magento-connect/catalog-search-refinement-free.html
Robots.txt para Magento
http://turnkeye.com/blog/optimize-robots-txt-for-magento/
Workflow de pedidos
http://go.magento.com/support/kb/entry/name/order-workflow
Cron en Magento
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job
![Page 13: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/13.jpg)
Caso práctico Distribuciones Exclusivas de Vinos de La Rioja, S.A (a.k.a. DEVILAR)
está orientada al mercado Europeo, por lo que tendrá 2 tiendas:
España en castellano y Reino Unido en inglés.
Algún producto sólo se puede vender en UK.
La de UK en libras con tasa de cambio fija (1GBP = 1,2349 EUR)
Los clientes con CIF válido entran al grupo de Clientes VIP.
Clientes VIP con precios especiales en algunos producto.
Para el producto Oferton de día, si te gastas más de 120€,
dicho producto tiene un 80% de descuento.
Filtros por: precio, graduación, municipio, añada.
Buscador busca en nombre, descripción y municipio.
El catálogo se muestra con IVA del 21% incluido.
El email de creación de pedido para usuarios registrados y no
registrados es el mismo y pone sólo “PEDIDO REGISTRADO”.
Crear sitemap.xml para es y uk.
Envío gratis para España con pedidos de >100€ y el resto 10€ de gastos.
Optimizar rendimiento para puesta en producción.
Aceptar Condiciones de compra al hacer el pedido y cumplir con EU Cookie.
![Page 14: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/14.jpg)
Magento DesignDía 2:
![Page 15: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/15.jpg)
La vista
![Page 16: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/16.jpg)
MVC?Prácticamente sí, pero no.
![Page 17: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/17.jpg)
![Page 18: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/18.jpg)
CONSECUENCIAS
1. Bloques y plantillas
2. Un bloque Una plantilla→
3. Objeto $this
![Page 19: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/19.jpg)
app/design/frontend/base/default/template/page/1column.phtml
Anidamiento de bloques
![Page 20: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/20.jpg)
Aquí falta algo...1. ¿Cómo le digo qué bloques quiero utilizar?
2. ¿Cómo especifico un bloque hijo?
![Page 21: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/21.jpg)
Layout (XML)
![Page 22: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/22.jpg)
Comprendiendo el Layout XML
- Etiquetas XML
- Añaden/modifican/eliminan relaciones entre bloques
- Relacionan bloques estructurales con bloques de contenido
- Controlar funciones y añadir contenido HTML
- En app/design/frontend/[package]/[theme]/layout
- Un archivo XML de Layout por cada módulo Magento
![Page 23: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/23.jpg)
Handles(manejadores)
- Elementos de primer nivel del nodo <layout>
- Cada uno representa un actualización del layout
- [nombre_modulo][nombre_controller][nombre_accion]
![Page 24: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/24.jpg)
Ejemplocontacs.xml
![Page 25: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/25.jpg)
Elementos del Layout
Reference
- Referenciar un bloque ya definido.
- Debe coincidir con el atributo name del bloque
Block
- Define un nuevo bloque
- Obligatorios los campos name y type
- <block type="page/html" template="example/view.phtml">
![Page 26: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/26.jpg)
Elementos del Layout
Remove
Action
- Define una acción a ejecutar
- Puede ser colocado dentro de reference o block
Update
- Carga un handle dentro de otro. Actualiza un bloque con el
contenido de otro.
![Page 27: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/27.jpg)
Ejemplocustomer.xml
![Page 28: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/28.jpg)
local.xml
HERENCIA
![Page 29: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/29.jpg)
Proceso derenderizado
![Page 30: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/30.jpg)
- Se instancian los bloques.
- Solo los bloques de tipo output son añadidos al response.
- Page.xml.
- Bloque raíz (root)
- Los bloques hijos se renderizan con la llamada getChildHtml()
- Proceso recursivo
![Page 31: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/31.jpg)
Bloques
![Page 32: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/32.jpg)
Tipos de bloques
1. Bloques estructurales
2. Bloques dinámicos
3. Bloques dinámicos con datos personalizados
4. Bloques estáticos
![Page 33: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/33.jpg)
Tipos de bloques
1. Bloques estructurales
2. Bloques dinámicos
3. Bloques dinámicos con datos personalizados
4. Bloques estáticos
![Page 34: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/34.jpg)
Bloques estructurales
- Encapsulan los bloques de contenido organizando
visualmente los bloques.
- Se pueden crear bloques estructurales personalizados
- Todos los bloques hijos de uno estructural se muestran automáticamente
sin tener que usar el método getChildHtml() para cada uno de ellos.
(Ejemplo: newreference.phtml)
![Page 35: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/35.jpg)
Bloques dinámicos (phtml) - Bloques Magento ( categoría, carrito, usuario,...)
- Representan el contenido y las funcionalidades
1. Vía layout XML (Ejemplo: review_form)
2. Desde el CMS
3. Desde la plantilla
–
![Page 36: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/36.jpg)
Bloques dinámicos personalizados
1. Vía layout XML
- Bloques personalizados
- Creamos un bloque y una plantilla asociada a este
personalizada.
2. Desde el CMS (Ejemplo: bestsellers)
![Page 37: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/37.jpg)
Bloques estáticos (CMS Blocks)
- Se crean desde el admin. CMS Bloques estáticos→
- Útil para que los clientes.
1. Vía layout XML
2. Desde el CMS
3. Desde la plantilla
![Page 38: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/38.jpg)
![Page 39: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/39.jpg)
Tipos de bloque (Layout XML)
1. page/html
2. page/html_head
3. page/html_header
4. page/html_wrapper
5. page/html_breadcrumbs
6. page/html_footer
7. page/template_links
8. page/switch
9. core/messages
10. core/text_list
11. core/proofiler
12. page/html_noticies
![Page 40: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/40.jpg)
¿Y tú que eres?Yo soy explorador de Magento
Rutas en plantilla
Sistema -> Configuración -> Developer -> Depurar
![Page 41: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/41.jpg)
Frontend de Magento
![Page 42: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/42.jpg)
Paquetes y temas
![Page 43: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/43.jpg)
Paquete
1. Colección de temas relacionados.
2. En Magento por defecto es “base”.
Tema
1. Varios por paquete.
2. Determina el contenido visual de nuestra tienda.
3. Solo puede pertenecer a un paquete.
![Page 44: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/44.jpg)
Tema
App/design
Archivos que controlan como se representan las plantillas.
Skin
Archivos que controlan el aspecto visual del tema (css, javascript).
![Page 45: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/45.jpg)
App/design
Layout
Contiene los archivos básicos XML que definen la estructura de bloque para
diferentes páginas.
Template
Archivos que contienen el PHP y el XHTML necesario para la representación
visual.
Locale
Contiene los CSV de traducción organizados por lenguaje.
![Page 46: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/46.jpg)
Tema por defecto
Todos los paquetes tiene el tema por defecto “default”.
![Page 47: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/47.jpg)
Directorios
Creando un nuevo tema
1. /app/design/frontend/new_package/new_theme/
2. /app/design/frontend/new_package/new_theme/layout
3. /app/design/frontend/new_package/new_theme/template
4. /skin/frontend/new_package/new_theme/
5. /skin/frontend/new_package/new_theme/css/
6. /skin/frontend/new_package/new_theme/images/
Archivos1. /app/design/frontend/new_package/new_theme/layout/local.xml
2. /skin/frontend/new_package/new_theme/css/local.css
![Page 48: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/48.jpg)
A practicar(crear nuestro tema)
![Page 49: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/49.jpg)
Admin CMS
![Page 50: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/50.jpg)
Páginas (CMS Pages)
Bloques estáticos (Static blocks)
Aplicaciones (Widgets)
![Page 51: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/51.jpg)
Tareas comunes en Magento
![Page 52: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/52.jpg)
- Añadir/quitar archivos/librerías
- Añadir/quitar enlaces a bloques
En plantilla
![Page 53: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/53.jpg)
- Cambiar parámetros de los bloques
- Diferentes acciones para logueados/no-logueados
- Añadir imágenes
En plantilla
![Page 54: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/54.jpg)
- Diseño personalizable por categoría Navegación por capas : Display settings Is Anchor → → yes
Incluir texto estático o imágenes.
- Navegación por capas Ocultar/Mostrar atributos.
Atributos filtrables con/sin resultados
- Página de producto Layout de la página de producto
Galería de imágenes
En el administrador
![Page 55: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/55.jpg)
Snippets
![Page 56: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/56.jpg)
Url de la página
<?php echo $this->getUrl('mypage'); ?>
Url de la imagen
<?php echo $this->getSkinUrl('images/button.gif'); ?>
Url del producto
<?php echo $this->getProductData()->getProductUrl(); ?>
Nombre del producto
<?php echo $this->htmlEscape($this->getProductData()->getName()); ?>
Mostrar todos los productos de una categoría
$categories = $_product->getCategoryIds();
foreach($categories as $k => $_category_id):
$_category = Mage::getModel('catalog/category')->load($_category_id);
<a href="<?php echo $_category->getUrl() ?>"><?php echo $_category->getName() ?>
<?php endforeach; ?>
–
![Page 57: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/57.jpg)
Comprobar si un usuario esta logueado
$logged_in = Mage::getSingleton('customer/session')->isLoggedIn();
Cargar producto según su SKU
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $product_sku);
Cargar producto según su ID
$_product = Mage::getModel('catalog/product')->load($product_id);
Cargar categoría según su ID
$_category = Mage::getModel('catalog/category')->load($category_id);
Obtener categoría actual
$_category = Mage::getModel('catalog/layer')->getCurrentCategory();
Obtener literal (para traducciones)
$text = $this->__('Content');
–
![Page 58: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/58.jpg)
La práctica
![Page 59: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/59.jpg)
1- Añadir enlace de Twitter en el apartado “Company” del pie.
2- Crear página “Condiciones de compra” y añadirla en los enlaces de la cabecera “Mi
Cuenta”.
3- Añadir un bloque estructural encima del pie donde aparezca un eslogan
4- Añadir un imagen (Enpresa Digitala) y que sea un enlace que lleve a su web en la
columna de la izquierda de la vista de categoría
5- Añadir una imagen/slider en nuestra “home”.
6- Modificar el valor “nofollow” al Meta tag robots
![Page 60: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/60.jpg)
Recursos útiles
Oficial Magento designer guide
http://www.magentocommerce.com/resources/magento-user-guide
Magento: The right way
http://magentotherightway.com/
Magento Cheat Sheet
http://www.richdynamix.com/mcheat/
![Page 61: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/61.jpg)
Magento DevelopmentDía 3:
![Page 62: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/62.jpg)
¿Herramientas?
![Page 63: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/63.jpg)
Herencia
Local Community Core→ →
![Page 64: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/64.jpg)
Crear un móduloapp/code/local/On4u/Holamundo/etc/config.xml
app/etc/modules/On4u_Holamundo.xml
![Page 65: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/65.jpg)
Registro de Helpers, Bloques y Modelos (I)
app/code/local/On4u/Holamundo/etc/config.xml
![Page 66: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/66.jpg)
Registro de Helpers, Bloques y Modelos (II)
app/code/local/On4u/Holamundo/Helper/Data.php
Lo mismo para:
app/code/local/On4u/Holamundo/Block
app/code/local/On4u/Holamundo/Model
La nomenclatura sigue la convención:
<Vendor namespace>_<Modulename>_<Objecttype>_<Classname>
Y para cargarlos:
Mage::getModel(“holamundo/ejemplo”);
Mage::helper(“holamundo/data”);
![Page 67: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/67.jpg)
Crear página
app/code/local/On4u/Holamundo/etc/config.xml
app/code/local/On4u/Holamundo/controllers/IndexController.php
http://mi-magento.com/holamundo/index/hola/
![Page 68: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/68.jpg)
app/code/local/On4u/Holamundo/etc/config.xml
~/layout/holamundo.xml
~/controllers/IndexController.php
Cargar layout
![Page 69: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/69.jpg)
app/code/local/On4u/Holamundo/etc/config.xml
Traducciones
Creamos el fichero app/locale/xx_XX/On4u_Holamundo.csv con las traducciones:
“Literal”, “Traducción”
Y para utilizarlo:
echo $this>__(“Literal a traducir”);
![Page 70: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/70.jpg)
app/design/frontend/mitema/default/template/holamundo/newproducts.html
app/design/frontend/mitema/default/layout/holamundo.xml
app/code/local/On4u/Holamundo/Block/Newproducts.php
Bloques
![Page 71: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/71.jpg)
app/code/local/On4u/Holamundo/etc/config.xml
app/code/local/On4u/Holamundo/Model/Catalog/Product.php
Reescribir una clase del core
![Page 72: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/72.jpg)
+350 tablas
2 tipos de entidades (flat y EAV)
Convención de nombres
![Page 73: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/73.jpg)
Algunas tablas
de core
![Page 74: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/74.jpg)
Tablas FLAT
![Page 75: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/75.jpg)
Conectar con BD de Magento
Conectar con otra BD externa
![Page 76: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/76.jpg)
Trabajando con SQL Querys
Trabajando con Colecciones (Mejor opción)
![Page 77: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/77.jpg)
Las entidades flat
La tabla de la base de datos
El objeto Model (lógica negocio)
El objeto Resource Model (conecta con BD p.e. save())
El objeto Resource Collection
![Page 78: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/78.jpg)
Tablas EAV
![Page 79: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/79.jpg)
Tipos de entidades:
catalog_category
catalog_product
creditmemo
customer
customer_address
invoice
order
shipment
Tipos de atributos:
Datetime
Decimal
Int
Varchar
Text
![Page 80: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/80.jpg)
Tablas EAV para productos
![Page 81: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/81.jpg)
Tablas Flat para entidades EAV
Ventajas:
Rendimiento
Desventajas:
Sincronización entre tablas (Magento Index)
Crece el tamaño del a base de datos
![Page 82: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/82.jpg)
app/code/local/On4u/Holamundo/etc/config.xml
Scripts de
instalación(core_resource)
![Page 83: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/83.jpg)
app/code/local/On4u/Holamundo/sql/holamundo_setup/install0.0.1.php
![Page 84: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/84.jpg)
Crear tablas flat desde el modelo
app/code/local/On4u/Holamundo/etc/config.xml
![Page 85: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/85.jpg)
Crear tablas flat desde el modelo (II)
![Page 86: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/86.jpg)
Crear tablas flat desde el modelo (III)
![Page 87: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/87.jpg)
Crear tablas flat desde el modelo (IV)
![Page 88: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/88.jpg)
Crear tablas flat desde el modelo (V)app/code/local/On4u/Holamundo/Model/Resource/Subscription/Collection.php
app/code/local/On4u/Holamundo/Model/Resource/Subscription.php
app/code/local/On4u/Holamundo/Model/Subscription.php
![Page 89: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/89.jpg)
Crear tablas flat desde el modelo (V)
app/code/local/On4u/Holamundo/controllers/IndexControllers.php
![Page 90: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/90.jpg)
Coleccionesapp/code/local/On4u/Holamundo/controllers/IndexControllers.php
Filtros
>addAttributeToFilter('entity_id', array ('in' => array(1, 7, 11)))
>addAttributeToFilter('name', array ('like' => '%Oxford%'))
Mostrar la Query
$productCollection>load();
Echo $productCollection>getSelect()>__toString();
Modificar datos
$productCollection>setDataToAll('price', 20); (al hacer save())
![Page 91: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/91.jpg)
Backend
app/code/local/On4u/Holamundo/etc/config.xml
app/code/local/On4u/Holamundo/controllers/Adminhtml/Holamundo/IndexController.php
http://mimagento.com/index.php/admin/holamundo_index
![Page 92: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/92.jpg)
Backend Menu
![Page 93: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/93.jpg)
Backend ACL
Mage::getSingleton('admin/session')>isAllowed('all')
![Page 94: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/94.jpg)
Configuración del
sistema
Mage::getStoreConfig('<path>')
![Page 95: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/95.jpg)
app/code/local/On4u/Holamundo/controllers/Adminhtml/Holamundo/SubscriptionController.php
Datagrid
app/code/local/On4u/Holamundo/Block/Adminhtml/Subscription.php
![Page 96: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/96.jpg)
Datagrid (II)app/code/local/On4u/Holamundo/Block/Adminhtml/Subscription/Grid.php
![Page 97: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/97.jpg)
Datagrid (III)
![Page 98: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/98.jpg)
Datagrid (IV)
![Page 99: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/99.jpg)
Clientesapp/code/local/On4u/Holamundo/sql/holamundo_setup/upgrade0.0.20.0.3.php
![Page 100: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/100.jpg)
Source models
![Page 101: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/101.jpg)
Eventos (crear)
app/code/local/On4u/Holamundo/controllers/IndexController.php
![Page 102: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/102.jpg)
Eventos (observer)app/code/local/On4u/Holamundo/etc/config.xml
app/code/local/On4u/Holamundo/Model/Observer.php
![Page 103: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/103.jpg)
Eventos (observer)app/code/local/On4u/Holamundo/etc/config.xml
app/code/local/On4u/Holamundo/Model/Observer.php
![Page 104: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/104.jpg)
Cronjobsapp/code/local/On4u/Holamundo/etc/config.xml
app/code/local/On4u/Holamundo/Model/Observer.php
![Page 105: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/105.jpg)
Para qué sirve un API
Interconectar sistemas para que se entiendan entre ellos (internet of things)
Aplicaciones distribuidas.
El servidor ofrece unos servicios y el cliente envía peticiones.
Interfaz abstracta reusable
Marshalling / Unmarshalling
![Page 106: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/106.jpg)
REST vs SOAP
● SOAP– Pros
● Fácil de automatizar (sobre todo Java y cía)
● Wsdl
– Contras● Implementaciones
anti-interoperabilidad● Demasiado verboso
● REST– Pros:
● Ubicuo● Estándar● Caching● Statleeess (escalabilidad)● JSON o XML o lo que sea.
– Contras● Herramientas● Autodocumentación /
Autogeneracion● Verbos limitados
![Page 107: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/107.jpg)
REST vs SOAP
![Page 108: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/108.jpg)
Seguridad
● Oauth● Basic● Tokens (!= sesiones, pero la misma idea)● Por oscuridad (NO USAR)
![Page 109: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/109.jpg)
API+
● Acceso granular (recuperar sólo lo necesario) y filtrado● Tipos bien definidos● “Desnormalizar” (reducir nº de peticiones)● Multiformato● Documentación y buenos errores *● Versionado● Disponibilidad y velocidad *
*Qué bueno es que haya niños Magentos para echarles la culpa.
![Page 110: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/110.jpg)
API REST Magento
● http(s)://magentohost/api/rest● Clientes, productos, inventario, pedidos(lectura)● OAuth1.0a● Métodos: GET, POST, PUT, DELETE● Filtros: page, order, dir, limit, etc.● ACL (admin, customer, guest) + roles +attributes● JSON + XML
![Page 111: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/111.jpg)
Elementos del API REST
● Módulo: Mage_Api2– API SOAP v1 → API SOAP v2 (1.3) != API REST
– No se trata de extenderlo sino de usarlo
● Request Interpreters y response renderers– URL query, json y xml
● Auth Adapters– Oauth
● User Types– Guest, customer, admin
● Route– entity / collection
● Request → Dispatcher → Response
![Page 112: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/112.jpg)
Elementos del API REST
● ACL:– Global y filter
– Deciden qué roles acceden a qué atributos. Se usa también como “filtro” para eliminar campos.
● Validator– Comprueba que los parámetros de entrada sean
correctos.
● Resource– Implementa la lógica de cada recurso
![Page 113: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/113.jpg)
Extendiendo un recurso
● La implementación está en cada módulo– Model/Api2/
● {Resourcename}.php● {Resourcename}/
– Rest.php– Rest/{Admin|Guest|Customer}/
● V{n}.php
– P.ej “CatalogInventory/Model/Api2/Stock”● Item.php● Item/Rest.php● Item/Rest/Admin/V1.php● Item/Validator/Item.php
![Page 114: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/114.jpg)
api2.xml
● El pegamento que une todas las partes● En /etc de cada módulo
– Resources (modelos)
– Atributos y roles (ACL)
– Rutas
– Validators
– Versiones disponibles
![Page 115: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/115.jpg)
Config (api2.xml)
app/code/core/Mage/CatalogInventory/etc/api2.xml
![Page 116: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/116.jpg)
Resource (Stock/Item.php)
app/code/core/Mage/CatalogInventory/Model/Api2/Stock/Item.php
![Page 117: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/117.jpg)
app/code/core/Mage/CatalogInventory/Model/Api2/Stock/Item/Rest.php
GET _retrieve→
POST _create→
PUT _update→
DELETE _delete→
![Page 118: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/118.jpg)
app/code/.../CatalogInventory/Model/Api2/Stock/Item/Rest/Admin/V1.php
![Page 119: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/119.jpg)
Recursos útiles
Guía de uso de GIT con Magento
https://www.sonassi.com/knowledge-base/our-magento-git-guide-and-work-flow/
Scripts para administrar Magento desde consola
https://github.com/classyllama/Wiz
Herramienta para reparar la Base de datos de Magento
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/db-repair-tool
Trabajar con colecciones
http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/using_collections_in_magento
![Page 120: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/120.jpg)
Caso práctico● Hola Mundo por pantalla
● Hola Mundo en un bloque con traducciones
● Crear bloque de nuevos productos
● Reescribir model de Product para poner CURSO delante del nombre
● Instalador que cree un atributo a producto
● Actualización que cree tabla de suscriptores
● Colección que muestre los productos que tiene una 'A'
● Acceso en menú de backend
● ACL de permisos
● Gestión de configuración
● Actualización que cree atributo a cliente
![Page 121: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/121.jpg)
Gracias ;)
![Page 122: Magento Best Practices](https://reader034.vdocument.in/reader034/viewer/2022052304/557b60fed8b42a90078b553b/html5/thumbnails/122.jpg)
www.on4u.es