Debug using zend: Debug with zend as a framework which develops with PHP to be used as a tool that effectively matches the complete pattern of making compulsive distinctions. In Magento website development use this the code snippet below and match it with the PHP code programming methodology, which you can apply when coding in a series of many ways.
<?php echo Zend_Debug::dump($thing_to_debug, 'debug'); ?> $_GET, $_POST & $_REQUEST Variables <?php // $_GET $productId = Mage::app()->getRequest()->getParam('product_id'); // The second parameter to getParam allows you to set a default value which is returned if the GET value isn't set $productId = Mage::app()->getRequest()->getParam('product_id', 44); $postData = Mage::app()->getRequest()->getPost(); // You can access individual variables like... $productId = $postData['product_id']); Get methods of an object First, use get_class to get the name of an object's class. <?php $class_name = get_class($object); ?> Then, pass that get_class_methods to get a list of all the callable methods on an object <?php $class_name = get_class($object); $methods = get_class_methods($class_name); foreach($methods as $method) { var_dump($method); } Is product purchasable? <?php if($_product->isSaleable()) { // do stuff } ?> Load Products by Category ID <?php $_category = Mage::getModel('catalog/category')->load(47); $_productCollection = $_category->getProductCollection(); if($_productCollection->count()) { foreach( $_productCollection as $_product ): echo $_product->getProductUrl(); echo $this->getPriceHtml($_product, true); echo $this->htmlEscape($_product->getName()); endforeach; } Magento Developmental Methods Get associated products Make the name of related products known and apply them in dealing when you retrieve them, as they are consistent and available through use of the below code snippet which you can apply intentionally. Make determination to associate different methods of connecting on the database and avail the selected products you know are your requirement to see items on your stores database. In /app/design/frontend/default/site/template/catalog/product/view/type/ <?php $_helper = $this->helper('catalog/output'); ?> <?php $_associatedProducts = $this->getAllowProducts() ?> <?php //var_dump($_associatedProducts); ?> <br /> <br /> <?php if (count($_associatedProducts)): ?> <?php foreach ($_associatedProducts as $_item): ?> <a href="<?= $_item->getProductUrl(); ?>"><?= $_helper->productAttribute($_item, $_item->getName(), 'name'); ?> | <?= $_item->getName(); ?> | <?= $_item->getPrice(); ?></a> <br /> <br /> <?php endforeach; ?> <?php endif; ?> Get An Array of Country Names/Codes in Magento <?php $countryList = Mage::getResourceModel('directory/country_collection') ->loadData() ->toOptionArray(false); echo '<pre>'; print_r( $countryList); exit('</pre>'); Create a Country Drop Down in the Frontend of Magento <?php $_countries = Mage::getResourceModel('directory/country_collection') ->loadData() ->toOptionArray(false) ?> <?php if (count($_countries) > 0): ?> <select name="country" id="country"> <option value="">-- Please Select --</option> <?php foreach($_countries as $_country): ?> <option value="<?= $_country['value']; ?>"> <?= $_country['label']; ?> </option> <?php endforeach; ?> </select> <?php endif; ?> Magento Program Making Return Product Attributes Get your product related information that is necessary and provides you the encrypted information which you want to know. Perceive through the code snippet the exact information that you will be looking for where you have several product with the coding doing the magic of providing you certain characteristics you need but never actually know it. In addition, another code snippet will tell you the complete number of items you are adding to your cart. <?php $_product->getThisattribute(); $_product->getAttributeText('thisattribute'); $_product->getResource()->getAttribute('thisattribute')->getFrontend()->getValue($_product); $_product->getData('thisattribute'); // The following returns the option IDs for an attribute that is a multiple-select field: $_product->getData('color'); // i.e. 456,499 // The following returns the attribute object, and instance of Mage_Catalog_Model_Resource_Eav_Attribute: $_product->getResource()->getAttribute('color'); // instance of Mage_Catalog_Model_Resource_Eav_Attribute // The following returns an array of the text values for the attribute: $_product->getAttributeText('color') // Array([0]=>'red', [1]=>'green') // The following returns the text for the attribute if ($attr = $_product->getResource()->getAttribute('color')): echo $attr->getFrontend()->getValue($_product); // will display: red, green endif; Format Price <?php $formattedPrice = Mage::helper('core')->currency($_finalPrice,true,false); } Cart Data <?php $cart = Mage::getModel('checkout/cart')->getQuote()->getData(); print_r($cart); $cart = Mage::helper('checkout/cart')->getCart()->getItemsCount(); print_r($cart); $session = Mage::getSingleton('checkout/session'); foreach ($session->getQuote()->getAllItems() as $item) { echo $item->getName(); Zend_Debug::dump($item->debug()); } Total items added in cart <?php Mage::getModel('checkout/cart')->getQuote()->getItemsCount(); Mage::getSingleton('checkout/session')->getQuote()->getItemsCount(); Total Quantity added in cart <?php Mage::getModel('checkout/cart')->getQuote()->getItemsQty(); Mage::getSingleton('checkout/session')->getQuote()->getItemsQty();
0 Comments
Leave a Reply. |