PHP SOLUTIONS

This is the blog for getting Idea regarding PHP, Magento, jQuery and JavaScript for Customization.

Wednesday, 5 October 2016

Magento 2 : Method to use SQL query

Hello Friends,

         Magento 2.X is use Resource Connection Method for fetch data from the Database, Which is little bit different from the Magento 1.X

        I have used code like below, and I hope it will helps to you also,

        Here, I show the code for SELECT query for magento2

 1)  $this->_resources= \Magento\Framework\App\ObjectManager::getInstance()
->get('Magento\Framework\App\ResourceConnection');
 2)  $connection = $this->_resources->getConnection();
 3)  $Table_Name = $this->_resources->getTableName('TABLE NAME');
4) $data = $connection->fetchAll('SELECT * FROM '.$Table_Name.' WHERE
Field_Name=Value');

       you just copy & paste this in related *.phtml or Controller files !

       If you want to use Insert or Update then just replace Select query, and it will work !

       For, Insert replace line number (4)

4) $data = $connection->fetchAll('INSERT into '.$Table_Name.'
VALUES ('value1','value2');

       For, Update replace line number (4)

4) $data = $connection->fetchAll('UPDATE '.$Table_Name.'
SET column1=value1,column2=value2 WHERE id=1;

This is working fine for me in Magento 2.0 !
       

Tuesday, 24 May 2016

Automatic item updates: Missing schema.org microdata availability information - Google Data Feed

Hi,

You have set auto update setting for you Google Data Feed. You can see the setting of Automatic item updates setting over here,

1) Click on setting on left sided menu list at bottom
2) Click on Automatic item updates
3) Can see Attributes to be updated

Now, Auto item updates very helpful for increase the site performance and give accurate details of sites to the end users.

such as, If your X product data feed price is $55.00 while upload data feed to google merchant but same X product price will change by $50.00 then google automatic update X product price to $50.00 to data feed.

suppose, If you are getting this type of warning from Google it means google can not crawl the product availability information from your particular product leading page OR what micro data you set its structure is wrong !

If you set Micro data information then you can check it with google tool, https://search.google.com/structured-data/testing-tool

If you didn't set the schema information for product leading page then you follow, http://www.schema.org/docs/gs.html

Here some necessary micro-data properties are

<div itemscope itemtype="http://schema.org/Product">

    1. <img itemprop="image" src="testing.jpg" alt="Test Demo"/>
    2. <span itemprop="name">Product Name</span>
    3. /*Product Pricing should under offers property*/
    4. <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
      1. <span itemprop="priceCurrency">USD</span>
      2. <span itemprop="price">100</span>
      3. <link itemprop="availability" href="http://schema.org/InStock" />
    5. </div>
</div>



Monday, 11 April 2016

Magento : Add last increment id of "sales_flat_quote_item" in another table

Magento
        $production = Mage::getSingleton('core/session')->getproValue($production); /* This is the session value which is set on Category/List page */
        $shipping = Mage::getSingleton('core/session')->getshipValue($ship);  /* This is the session value which is set on Category/List page */

/* This is code for Change Row Data of the product in cart and add Shipping charge in to that product into cart
         * Changes By Rixit
        // */
       
            $connection = Mage::getSingleton('core/resource')
            ->getConnection('core_read');
            $select = $connection->select()
            ->from('sales_flat_quote_item', array('MAX(item_id) as itn')); // select * from tablename or use array('id','name') selected values  
            $rowsArray = $connection->fetchAll($select); // return all rows
            $rowArray =$connection->fetchRow($select);   //return row
       
            $temp = $rowArray['itn'];
           
            $select1 = $connection->select()
            ->from('sales_flate_lastinsertd_id', array('MAX(last_inserted_id) as itn1')); // select * from tablename or use array('id','name') selected values  
            $rowsArray = $connection->fetchAll($select1); // return all rows
            $rowArray =$connection->fetchRow($select1);   //return row
       
            $itnew = $rowArray['itn1'];
       
            if( ($temp != $itnew) && ($temp >= $itnew) )
            {   
                $total = $production + $shipping;
       
                $connection = Mage::getSingleton('core/resource')
                ->getConnection('core_write');
       
                $connection->beginTransaction();
                $fields = array();
                $fields['last_inserted_id']= $temp;
                $fields['production_time']= $production;
                $fields['shipping_time']= $shipping;        
                $fields['total']= $total;        
                $connection->insert('sales_flate_lastinsertd_id', $fields);
                $connection->commit();
                               
            }
            else
            {
                //echo "Riisdfs";
            }
           
        /*
         * End of Changes By Rixit
        // */

Thursday, 7 April 2016

Command Promt : php is not recognized as an internal or external command

Set PHP environment variable to the System for run PHP from CMD (Command Prompt)
Step 1 : Open properties of My Computer (Right Click on My Computer)

Step 2 : Click on "Advance system settings"

 Step 3 : Can see popup of  "System Properties"

              Click on "Environment Variable" button


 Step 4 : Can see popup of Environment Variable

              Set System variable path for PHP 


              Append C:\wamp\bin\php\php5.5.12; at last  (Note :- replace php5.5.12 with your php version)

     

Step 5 : Close / Open CMD (Command Prompt) again
Now, It's solved !
, ,

Magento 2 : CSS and Javascript no loading after installation

    This is an initial issue with magento 2, After Installation Front-End and Back-End CSS / JS do not work.

    Using following steps, it is getting work easily for magento 2 !

    This is creating frontend / adminhtml directory to the "pub/static/" directory.

Using Command Prompt(CMD) set CSS & JS for Magento2

Step 1 : Run CMD

Step 2 : Goto Magento installation directory using

             CD wamp/www/[Magento dir.]

Step 3 : Run

             php bin/magento setup:static-content:deploy

             If you are getting problem of

            "php is not recognized as an internal or external command" [Click here...]

Step 4 : Run

             php bin/magento indexer:reindex

Step 5 : Delete Cache from

             var/cache/[delete all dir.]

It's getting work for Front-end & Back-end !
,