viernes, 18 de abril de 2014

MAGENTO: Virtual host de NGINX para MAGENTO

Precondiciones:
  1. Tener instalado y funcionando NGINX y php-fpm
Variables:
  • {serverRoot}
    • Ruta donde se encuentra nuestra tienda.
  • {serverName}
    • Nombre de nuestro servidor.
  • {codigoTienda}
    • Código en MAGENTO de la tienda.
Consideraciones:
En instalaciones multitienda y por cuestiones de rendimiento se aconseja crear un virtualhost por cada tienda.


Proceso:
En el directorio de sites_enabled de NGINX crear el archivo {serverName}, con el siguiente contenido:

server {
    listen   80;
    root {serverRoot};
    index index.php;

    server_name {serverName};

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
        access_log        off;
        expires           30d;
        add_header Cache-Control "public";
    }

    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }

     location / {
         if ($uri ~ "^(.+.php)(/.+)") {
                set $path_info $1;
        }

        if (!-e $request_filename) {
            rewrite ^(.+)$ /index.php;
        }
    }

    fastcgi_param PATH_INFO $path_info;

    location ~ \.php$ {

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;

        expires        off; ## Do not cache dynamic content
        fastcgi_buffer_size 256k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_read_timeout 120;

        fastcgi_param  MAGE_RUN_CODE {codigoTienda};

    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }

}

Recargarmos la configuración de NGINX y listo :D

sudo service nginx reload


MAGENTO: En subdirectorio de NGINX

Precondiciones:
  1. Tener funcionando NGINX con PHP
  2. Tener instalado MAGENTO como subdirectorio en el root de NGINX
Variables:
  • {miTienda}
    • Nombre del subdirectorio donde se encuentra Magento.
  • {admin}
    • Identificador del backend de nuestra tienda.
Proceso:

En el archivo de configuración de sitio de nginx, en mi caso

/etc/nginx/sites-enabled/default

Agregamos los siguientes location:

  location /{miTienda} {
        index index.php;
        try_files $uri $uri/ @handler;
        expires 30d;
        if ($uri ~ "^/index.php/{admin}.*$"){
            rewrite ^/index.php/
{admin}(.*) /{admin}$1 redirect;
        }
    }

    location ~ ^/{miTienda}/(app|includes|var|lib|media/downloadable|pkginfo|report/config.xml|var)/  {
       deny all;
    }

    location @handler { 
        rewrite / /{miTienda}/index.php; 
    }

UBUNTU: Migrar de APACHE a NGINX


Precondiciones:
  1. Tener apache funcionando
  2. Tener php5 funcionando en apache
Paso 1:
Remover apache, así sin más, sin miedo:


sudo apt-get remove apache2*


Paso 2:

Instalar php5-fpm con sus dependencias, este paso podría disparar algunos mensajes sobre algunos paquetes ya instalados:

sudo apt-get install php5-common php5-cli php5-fpm


Paso 3:
Instalamos nginx

sudo apt-get install nginx

Paso 4:
Comienzan las configuraciones :D, primero php-fpm

En el archivo:


    /etc/php5/fpm/pool.d/www.conf

 
Buscar la variable listen, que por default viene como:


    listen = 127.0.0.1:9000


La modificamos a:


    listen = /var/run/php5-fpm.sock


Tomen en cuenta el valor que asignen a listen, por que ese valor mas el prefijo "unix:" deben coincidir con la variable fastcgi_pass de nginx pues ese sera el socket por el que se comunicaran php y nginx.

 
Ahora nginx, en el arcivo:


    /etc/nginx/sites-enabled/default

Vamos primero a modificar la variable root, para no tener que mover nuestros proyectos actuales


root /var/www;

Luego de ello, buscamos el location que nos propone nginx para manejar las peticiones de php, y descomentamos las lineas necesarias para que quede algo así:


    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        # With php5-cgi alone:
        #fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

  
Noten que la variable fastcgi_pass tiene el prefijo "unix:" y el valor que le dimos a la variable listen de php-fpm, si dicha condición no se cumple la configuración no funcionara.

También sugiero agregar el siguiente location, para mejorar la descarga de imágenes y contenido estático
:

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico)$ {
            access_log        off;
            expires           30d;
            add_header Cache-Control "public";
    }


Por ultimo agregamos el siguiente location, el cual impedirá el acceso a los archivos .htaccess de apache


    location ~ /\.ht {
        deny all;
    }


Bueno, al llegar a este punto solo nos queda una cosa por hacer


sudo service nginx restart

Y si todo salío como debe, visiten http://localhost y bienvendios a NGINX, y si no, como dice Kick Butowsky "Live Till It Hurts"

martes, 1 de abril de 2014

Magento: Prevenir Envío de correos

Precondiciones:

Tener la base instalada.

Evitar mandar correos a los clientes:

UPDATE customer_entity
SET email = 'some@mail.com'
WHERE email != 'other@mail.com';

Evitar mandar correos a los usuarios

UPDATE core_config_data ccd
SET ccd.value = 'some@mail.com'
WHERE ccd.value LIKE '%@%';

Evitar mandar correos sobre ordenes y carritos
UPDATE sales_flat_order
SET customer_email = 'unexistent@mail.com'
WHERE customer_email != 'finalmau@gmail.com';

UPDATE sales_flat_quote
SET customer_email = 'unexistent@mail.com'
WHERE customer_email != 'finalmau@gmail.com';

viernes, 12 de abril de 2013

Magento: Borrar Pedidos de Prueba


Otro de c&p

SET FOREIGN_KEY_CHECKS=0;

TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;
TRUNCATE `sales_flat_order`;
TRUNCATE `sales_flat_order_address`;
TRUNCATE `sales_flat_order_grid`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sales_flat_order_payment`;
TRUNCATE `sales_flat_order_status_history`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_quote_payment`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;
TRUNCATE `sales_invoiced_aggregated`;
TRUNCATE `sales_invoiced_aggregated_order`;
TRUNCATE `log_quote`;
TRUNCATE `downloadable_link_purchased`;
TRUNCATE `downloadable_link_purchased_item`;
TRUNCATE `eav_entity_store`;

ALTER TABLE `sales_flat_creditmemo_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_creditmemo_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_invoice_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_status_history` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_comment` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_grid` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_shipment_track` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated` AUTO_INCREMENT=1;
ALTER TABLE `sales_invoiced_aggregated_order` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `downloadable_link_purchased` AUTO_INCREMENT=1;
ALTER TABLE `downloadable_link_purchased_item` AUTO_INCREMENT=1;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;

SET FOREIGN_KEY_CHECKS=1;

Magento: Borrar Productos de Pruebas


Simple y sencillo, un c&p

SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_product_bundle_option`;
TRUNCATE TABLE `catalog_product_bundle_option_value`;
TRUNCATE TABLE `catalog_product_bundle_selection`;
TRUNCATE TABLE `catalog_product_entity_datetime`;
TRUNCATE TABLE `catalog_product_entity_decimal`;
TRUNCATE TABLE `catalog_product_entity_gallery`;
TRUNCATE TABLE `catalog_product_entity_int`;
TRUNCATE TABLE `catalog_product_entity_media_gallery`;
TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
TRUNCATE TABLE `catalog_product_entity_text`;
TRUNCATE TABLE `catalog_product_entity_tier_price`;
TRUNCATE TABLE `catalog_product_entity_varchar`;
TRUNCATE TABLE `catalog_product_link`;
TRUNCATE TABLE `catalog_product_link_attribute`;
TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
TRUNCATE TABLE `catalog_product_link_attribute_int`;
TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
TRUNCATE TABLE `catalog_product_link_type`;
TRUNCATE TABLE `catalog_product_option`;
TRUNCATE TABLE `catalog_product_option_price`;
TRUNCATE TABLE `catalog_product_option_title`;
TRUNCATE TABLE `catalog_product_option_type_price`;
TRUNCATE TABLE `catalog_product_option_type_title`;
TRUNCATE TABLE `catalog_product_option_type_value`;
TRUNCATE TABLE `catalog_product_super_attribute`;
TRUNCATE TABLE `catalog_product_super_attribute_label`;
TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
TRUNCATE TABLE `catalog_product_super_link`;
TRUNCATE TABLE `catalog_product_enabled_index`;
TRUNCATE TABLE `catalog_product_website`;
TRUNCATE TABLE `catalog_product_entity`;

TRUNCATE TABLE `cataloginventory_stock`;
TRUNCATE TABLE `cataloginventory_stock_item`;
TRUNCATE TABLE `cataloginventory_stock_status`;

INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');

SET FOREIGN_KEY_CHECKS = 1;