Category : PHP

Doctrine Console Commands

Example doctrine console command: php vendor/bin/doctrine orm:generate-entities –help Available commands: dbal:import Import SQL file(s) directly to Database. dbal:run-sql Executes arbitrary SQL directly from the command line. orm:clear-cache:metadata Clear all metadata cache of the various cache drivers. orm:clear-cache:query Clear all query cache of the various cache drivers. orm:clear-cache:result Clear result cache of the various cache drivers.

Read More →

View array content in twig

The dump function dumps information about a template variable. It can be used as an alternative to var_dump or print_r from php. This is mostly useful to debug a template that does not behave as expected by introspecting its variables: {{ dump(var_name) }} Read entire article at: Twig -> Functions -> dump

Zend Framework 1 – trace and log sql errors and exceptions

Zend Framework 1 – trace sql errors and exceptions and put them in a log file. Add the next code in the ErrorController.php: <?php class ErrorController extends Zend_Controller_Action { … public function errorAction() { … if (get_class($errors->exception) == ‘Zend_Db_Statement_Exception’) { $writer = new Zend_Log_Writer_Stream(“ADD HERE YOUR LOG PATH”); $logger = new Zend_Log($writer); $logger->info($errors->exception); } …

Read More →

Magento – Categories Images

Get category image: <?php $_category = $this->getCurrentCategory(); $_imageUrl = $this->getImageUrl(); ?> Get category thumbnail: <?php $_category = $this->getCurrentCategory(); $_imageUrl = $this->getThumbnail(); ?>

PHP – SOAP sample

PHP simple SOAP sample SOAP server file (soapserver.php): <?php // Set a function in SOAP server file function hello($someone) { return “Hello ” . $someone . “!”; } // Create a new SOAP server $server = new SoapServer(null, array(‘uri’ => “urn://g31.local/ex/res”)); // Add function to SOAP server $server->addFunction(“hello”); // Handle SOAP server $server->handle(); ?> SOAP

Read More →

Magento get child products for a configurable product

Magento get products childs for a configurable product // $currentProduct = $this->getProduct(); $configurable_products = Mage::getModel(‘catalog/product_type_configurable’)->setProduct($currentProduct); $products_collection = $configurable_products->getUsedProductCollection()->addAttributeToSelect(‘*’)->addFilterByRequiredOptions(); foreach($products_collection as $_product){ echo $_product->getId() . “: ” . $_product->getName(); }

Magento – Show Quantity Box in Products List

In file ‘list.phtml’ file change the <button> line near line 108 from this: <?php if($_product->isSaleable()): ?> <button class=”form-button” onclick=”setLocation(‘<?php echo $this->getAddToCartUrl($_product) ?<‘)”>>span> <?php echo $this->__(‘Add to Cart’) ?></span></button> with: <form action=” <?php echo $this->getAddToCartUrl($_product) ?>” method=”post” id=”product_addtocart_form_<?php echo $_product->getId(); ?>”> <input name=”qty” type=”text” class=”input-text qty” id=”qty” maxlength=”12″ value=” <?php echo $this->getMinimalQty($_product) ?>” /> <button class=form-button”

Read More →

Magento – use singleton database connection

Magento database connection write mode: $db = Mage::getSingleton(‘core/resource’)->getConnection(‘core_write’); Magento database connection read mode: $db = Mage::getSingleton(‘core/resource’)->getConnection(‘core_read’); Query model $result = $db->query(“SELECT * FROM tablename”); if ($result) { while ($row = $result->fetch(PDO::FETCH_ASSOC)) { // Use $row } }

Magento – custom block

Custom block (for CMS pages): {{block type=”core/template” name=”template_name” template=”mydir/mytemplate.phtml” }}

1 2 3 4