Laboratori de
Desenvolupament*
Albert Serra
Senior PHP Developer:
Symfony Framework / Blackberry / XT-Commerce
Symfony 1.2 – Crear scripts executables per consola (create task)
Symfony Framework 1.2
El proposit es la creació de scripts o tasques executables des de consola, per poder-ho cridar des del CRON o sigui cridable per a altres aplicacions d’entorn de consola (BATCH)
El symfony anomena Task els processos executables des de consola i es pot fer servir tota les funcionalitats del framework.
Per crear una simple tasca s’ha de crear una classe que hereti de sfBaseTask i guardar-la en el directori lib/tasks/ “Tasca.class.php”
Per crear la tasca utilitzarem la comanda:
php symfony generate:task namespace:task
El namespace és un nom per agrupar diferents tasques amb accions semblants, això ens generarà la classe: namespaceNameTask.class.php
Imaginem que tenim accions que engloben un usuari, com per exemple usuari:newsletter i usuari:privatemessage les classes ens quedaran:
usuariNewsletterTask.class.php
usuariPrivatemessage.class.php
Tenim més opcions per configuracions alternatives, amb descripció, si volem propel o no i altres opcions que es mostraran amb:
php symfony help generate:task
Un exemple de task:
class twitterUpdateTask extends sfBaseTask
{
protected function configure()
{
// // add your own arguments here
// $this->addArguments(array(
// new sfCommandArgument('my_arg', sfCommandArgument::REQUIRED, 'My argument'),
// ));
$this->addOptions(array(
new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'Twitter update messages'),
new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel'),
// add your own options here
));
$this->namespace = 'twitter';
$this->name = 'update';
$this->briefDescription = '';
$this->detailedDescription = <<configuration);
$connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
// add your code here
// here my code! thanks!
// seleccionem en base de dades
$c = new Criteria();
$c->add(MortPeer::TWITTERCACHE,1);
$morts = MortPeer::doSelect($c);
// connectem al twitter
$twitter = new Twitter(sfConfig::get('app_twitter_user'),sfConfig::get('app_twitter_passwd'));
foreach($morts as $mort) {
$hashtags = array('#' . $mort->getTwNormalized(), '#rib_' . $mort->getTwNormalized());
foreach($hashtags as $h) {
$json = $twitter->search('search', 'get', 'json',array('q' => $h,'locale' => 'es'), false);
$tweets = json_decode($json, true);
if(is_array($tweets) && array_key_exists('results', $tweets)) {
$adds = TwitterCachePeer::addByHashtag($h, $tweets['results']);
$this->log($h . ': ' . $adds . ' cached');
}
}
}
}
}
Indexhibit - Multilanguage // Definitive solution
Indexhibit d0.7
UPDATED: New indexhibit laboratory in: indexhibit.albertserra.com
Creada una solució definitiva per transformar Indexhibit a multillenguatge. Es tradueix el contingut, el títol i les seccions, duplicant els camps a l'administració i a la base de dades basant-nos amb el estàndard i18n. Teniu una captura més aball:Creada una solución definitiva para transformar Indexhibit a multilenguaje. Se traduce el contenido, el título y las secciones, duplicando campos en la administración y en la base de datos siguiendo el estándar i18n. Tenéis una captura debajo:
Created a definitive solution to transform the Indexhibit to multilanguage. Content, title and sections had been translated, doubling fields in the administration and database using the standard i18n. You have a screenshot below:
Demo: indexhibit.albertserra.com
Update your Products Ordered count
xt-commerce
Sometimes the count of the "products ordered" (table: products, field: products_ordered) is not real. It contains the user installation order test, delete orders or others irrelevant orders. Easy to solve, next query update the product_ordered counting the order table.
Query to update the product_ordered, execute it in your MySQL Query Manager (like PhpMyAdmin)
UPDATE products
SET products_ordered = (
SELECT SUM( products_quantity ) AS total
FROM orders_products
WHERE orders_products.products_id = products.products_id
GROUP BY products_id)
Manufacturers in product detail (product_info)
xt-commerce
Show the manufacturer logo in the product info table. This replace the manufacturer block in the sidebar.
Modify action: includes/modules/product_info.php
$manufacturer = "SELECT * FROM manufacturers
LEFT JOIN manufacturers_info ON manufacturers.manufacturers_id = manufacturers_info.manufacturers_id
WHERE
manufacturers.manufacturers_id = ".$product->data['manufacturers_id']."
AND languages_id = '".$_SESSION['languages_id']."'";
$manufacturer = xtDBquery($manufacturer);
$manufacturer = xtc_db_fetch_array($manufacturer);
$info_smarty->assign('MANUFACTURER_NAME',$manufacturer['manufacturers_name']);
$info_smarty->assign('MANUFACTURER_IMG','/images/' . $manufacturer['manufacturers_image']);
$info_smarty->assign('MANUFACTURER_URL',xtc_manufacturer_link($manufacturer['manufacturers_id'],$manufacturer['manufacturers_name']));
Modify template: includes/modules/product_info.php
Show the customer phone in print orders
xt-commerce
A lot of times you need to have a customer phone in the print orders: for the shipping or your paper order control. That's is the solution:
Your have a table in the database named "address format". We have to update adding "$cr$phone":
-- SQL UPDATE TABLE ADDRESS_FORMAT UPDATE `address_format` SET `address_format` = '$firstname $lastname$cr$streets$cr$city, $postcode$cr$statecomma$country$cr$phone' WHERE `address_format`.`address_format_id` =1 LIMIT 1 ; UPDATE `address_format` SET `address_format` = '$firstname $lastname$cr$streets$cr$city, $state $postcode$cr$country$cr$phone' WHERE `address_format`.`address_format_id` =2 LIMIT 1 ; UPDATE `address_format` SET `address_format` = '$firstname $lastname$cr$streets$cr$city$cr$postcode - $statecomma$country$cr$phone' WHERE `address_format`.`address_format_id` =3 LIMIT 1 ; UPDATE `address_format` SET `address_format` = '$firstname $lastname$cr$streets$cr$city ($postcode)$cr$country$cr$phone' WHERE `address_format`.`address_format_id` =4 LIMIT 1 ; UPDATE `address_format` SET `address_format` = '$firstname $lastname$cr$streets$cr$postcode $city$cr$country$cr$phone' WHERE `address_format`.`address_format_id` =5 LIMIT 1 ;
Finally, add the line "$phone ..." in admin/include/functions/generals.php
function xtc_address_format($address_format_id, $address, $html, $boln, $eoln) {
$address_format_query = xtc_db_query("select address_format as format from ".TABLE_ADDRESS_FORMAT." where address_format_id = '".$address_format_id."'");
$address_format = xtc_db_fetch_array($address_format_query);
$company = addslashes($address['company']);
$firstname = addslashes($address['firstname']);
$cid = addslashes($address['csID']);
$lastname = addslashes($address['lastname']);
$street = addslashes($address['street_address']);
$suburb = addslashes($address['suburb']);
$city = addslashes($address['city']);
$state = addslashes($address['state']);
$country_id = $address['country_id'];
$zone_id = $address['zone_id'];
$postcode = addslashes($address['postcode']);
$phone = addslashes('Tel. ' . $address['telephone']);
$zip = $postcode;
$country = xtc_get_country_name($country_id);
$state = xtc_get_zone_code($country_id, $zone_id, $state);
if ($html) {
// HTML Mode
$HR = '
';
$hr = '
';
if (($boln == '') && ($eoln == "\n")) { // Values not specified, use rational defaults
$CR = '
';
$cr = '
';
$eoln = $cr;
} else { // Use values supplied
$CR = $eoln.$boln;
$cr = $CR;
}
} else {
// Text Mode
$CR = $eoln;
$cr = $CR;
$HR = '----------------------------------------';
$hr = '----------------------------------------';
}
$statecomma = '';
$streets = $street;
if ($suburb != '')
$streets = $street.$cr.$suburb;
if ($firstname == '')
$firstname = addslashes($address['name']);
if ($country == '')
$country = addslashes($address['country']);
if ($state != '')
$statecomma = $state.', ';
$fmt = $address_format['format'];
eval ("\$address = \"$fmt\";");
$address = stripslashes($address);
if ((ACCOUNT_COMPANY == 'true') && (xtc_not_null($company))) {
$address = $company.$cr.$address;
}
return $address;
}
Show the custumer name in cart box
xt-commerce
For a more personal treatment with your customer, you can show the customer name in the cart box. If you prefer, you can show "Guest" for the new visitant like image:
Add this code in the: templates/yourtemplate/source/boxes/shopping_cart.php
$welcome = HELLO . ' ' . $_SESSION["customer_first_name"] . '';
if ($_SESSION['cart']->count_contents() > 0) $welcome .= ', ' . HELLO_PRODUCTS;
$box_smarty->assign('WELCOME',$welcome);
Add the line in the template: templates/yourtemplate/boxes/box_cart.html
<td class="infoBox_right" align="left">
<table width="95%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td class="boxText">
{$WELCOME}
Prototype & Scriptaculous to build a Banner in a homepage
xt-commerce
Build a dynamic banner in the homepage. It switch between ten administrable multi-language images and links.
Programar TPV SERMEPA en OsCommerce o xt-commerce (La caixa / caja madrid) // Credit card module
OsCommerce / xt-commerce
El módul que ve per defecte en oscommerce o xt-commerce no es utilitzable en serveis de SERMEPA. Per defecte, esta prefabricat per demanar només els números de la targeta i apuntar contra un webservice. La passarel.la de SERMEPA no funciona d'aquesta manera i s'ha de reprogramar.S'haurà d'afegir un hack al fitxer: catalog/includes/modules/payment/cc.php, d'aquesta manera:
El módulo que viene por defecto en oscommerce o xt-commerce no es usable en servicios de SERMEPA. Por defecto, esta prefabricado para pedir solo los números de la targeta y apuntar contra un webservice. La pasarela de SERMEPA no funciona de esta manera y se tiene que reprogramar. Así que se tendra que parchear el fichero: catalog/includes/modules/payment/cc.php, de esta manera:
// payment modules tpv
// catalog/checkout_confirmation.php
// catalog/includes/modules/payment/cc.php
if($_SESSION['payment'] == "cc" or !$_SESSION['payment']) {
echo tep_draw_form('checkout_confirmation', 'https://sis.sermepa.es/sis/realizarPago', 'post');
} else {
echo tep_draw_form('checkout_confirmation', $form_action_url, 'post');
}
echo '' . MODULE_PAYMENT_CC_TEXT_TITLE . ' ';
?>
Substituint els paràmetres pels que et proporciona SERMEPA.Substituyendo los parámetros por los que te proporciona SERMEPA.
Puedes alquilar mis servicios contactando conmigo.