Saturday 12 August 2017

SoftException in Application.cpp:668: is writable by group

500 Error: File is writable by group

On occasion you may get a 500 page error (a blue/green error) when trying to run a PHP file in your account. When checking the error log which you can do via the cPanel account log in you may see the following line:

[Sat Aug 12 00:57:37 2017] [error] [client 103.240.34.54] SoftException in Application.cpp:668: Directory "/home/username/public_html/index.php" is writeable by group

This is due to the server running SuPHP and the files having higher permissions than allowed, 
 
How to solve this issue
 
Fix this problem you need to make sure your files are chmod 644 for all PHP based files and 755 for directories in order for them to work with SuPHP. You can easily do this by connecting via FTP with Filezilla Not from Cpanel and right clicking on the problem folders and files and selecting file permissions. Also set  0755 permission on public_html directory.

Saturday 22 July 2017

How to get the latest record in each group using GROUP BY


In PHP MySQL

SELECT `main_table`.`rebate_amount`, `main_table`.`companyname`, (SELECT target FROM batecash WHERE id = MAX(main_table.id)) AS `maxtarget`, SUM(rebate_amount) AS `rebate_amount`, SUM(invoiceamount) AS `purchase_amount`, MAX(id) AS `max_id`, `main_table`.`rebatetarget`, YEAR(created_at) yr, QUARTER(created_at) qt FROM `batecash` AS `main_table` WHERE (customerid = '5') GROUP BY YEAR(created_at), QUARTER(created_at) ORDER BY `created_at` DESC

 In Magento

$rebatecount = Mage::getModel('rebatereward/batecash')->getCollection()
                    ->addFieldToSelect('rebate_amount')
                    ->addFieldToSelect('companyname')
                    ->addFieldToFilter('orderstatus', array('eq' => 'completed'))
                    ->addFieldToFilter('addressid', array('eq' => $address->getId()))
                    ->addFieldToFilter('customerid', array('eq' => $this->getCustomer()->getId()));

            $rebatecount->getSelect()->columns("(SELECT rebatetarget FROM batecash WHERE id = MAX(main_table.id)) as maxtarget");
            $rebatecount->getSelect()
                    ->columns('SUM(rebate_amount) as rebate_amount')
                    ->columns('SUM(invoiceamount) as purchase_amount')
                    ->columns('MAX(id) as max_id')
                    ->columns('rebatetarget')
                    ->columns('YEAR(created_at) yr, QUARTER(created_at) qt')
                    ->group('YEAR(created_at), QUARTER(created_at)')
                    ->order(array('created_at DESC'));

Wednesday 19 July 2017

Which table truncate for magento speed optimised

SET foreign_key_checks = 0;
TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
TRUNCATE catalog_compare_item;
SET foreign_key_checks = 1;

Friday 9 June 2017

Test email in order email notification in magento

Add following function into any frontend controller and check via URL

public function sendtestAction()
    {
        $order = Mage::getModel('sales/order');
        $incrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
        $order->loadByIncrementId($incrementId);
        echo $incrementId;
        try {
            echo $order->sendNewOrderEmail();
        } catch (Exception $ex) {
            echo "Email Not Sent...";
        }
        $customer = Mage::getSingleton('customer/session')->getCustomer();
        $email = $customer->getEmail(); //End Email Sending
        echo '<pre>Done';
        echo $email;exit;
    }

Friday 28 April 2017

Pagination on shopify collection page with linklist

<h1 class="desktop-6 desktop-push-3 tablet-3 mobile-3">
  {% if collection.handle == 'all' %}{{ 'collections.general.all_products' | t }}
  {% elsif collection.handle == 'e-juice' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'a-d' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'e-i' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'j-m' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'n-z' %}
      E JUICE BRANDS
  {% else %}
  {{ collection.title }}
  {% endif %}
</h1>



<div class="clear"></div>
{% if linklists[collection.handle].links.size > 0 %}

<div class="collsn_img_link">
    {% if collection.image %}
    <img src="{{ collection | img_url: 'master' }}"  alt="{{ collection.title | escape }}" />
    {% endif %}
  </div>

<div class="rte">
    {{ collection.description | remove: "[banner]" }}
  
  </div>
{% endif %}
{% if linklists[collection.handle].links.size > 0 %}

<div class="desktop-12 tablet-6 mobile-3 collecsn-linklist ">
  {% comment %}
   <p class="chose-categry">Choose a sub category:-</p>
  {% endcomment %}
      {% assign collections = linklists[collection.handle].links %}
    {% paginate collections by 40 %}
     {% assign currentpage = paginate.current_page %}
      {% assign current_offset = paginate.current_offset %}
    {% assign offset_limit = paginate.current_offset | plus:40 %}
  <ul id="myList" >
  {% for collection_link in collections %}
    {% assign forindex = forloop.index %}
    {% if current_offset < forindex and offset_limit >= forindex %}
    <li class="desktop-3 tablet-3 mobile-3 {% cycle ' first', '', '', ' last' %}">
      {% assign collection = collection_link.object %}
      {% if collection_link.type == 'collection_link' %}
      <div class="collection-image">
        <a href="{{ collection.url }}" title="{{ collection_title }}">
          {% if collection.image %}
          {{ collection.image.src | collection_img_url: 'large' | img_tag: collection_title }}
          {% else %}
          {{ collection.products.first.featured_image | product_img_url: 'large' | img_tag: collection_title }}
          {% endif %}
          <h3>{{ collection_link.title }}</h3>
        </a>    
      </div>
      {% else %}
        <div class="collection-info-inner">     
          <h3>{{ collection_link.title | link_to: collection_link.url }}</h3>
        </div>
      {% endif %}
<!--           <div class="collection-info-inner"> -->
<!--             <a href="{{ collection.url }}" title="{{ collection_title }} collection"> -->
<!--               <h3>{{ link.title | link_to: link.url }}</h3> -->
<!--             </a> -->
<!--        </div> -->
    </li>
    {% endif %}
    {% endfor %}
  </ul>
{% include 'pagination' %}
{% endpaginate %}
  <div class="clear"></div>
<!--   <div id="loadMore">See more</div> -->
  </div>
{% else %}
{% paginate collection.products by 40 %}
<!-- Start Sidebar -->
{% if settings.collection_sidebar %}
{% include 'collection-sidebar' %}
{% endif %}
<!-- End Sidebar -->


<div class="{% if settings.collection_sidebar %}desktop-9 tablet-6{% else %}desktop-12 tablet-6{% endif %} mobile-3">

  <div id="collection-description" class="desktop-12 tablet-6 mobile-3">

<div class="collsn_img">
    {% if collection.image and collection.handle != "candy"%}
    <img src="{{ collection | img_url: 'master' }}"  alt="{{ collection.title | escape }}" />
    {% endif %}
  </div>

<div class="rte" contenteditable="true" spellcheck="false">
    {{ collection.description | remove: "[banner]" }}
  
  </div>
</div>
  {% if settings.collection_sidebar == false %}
  {% if settings.filters %}
  <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
    {% include 'filter' %}
  </div>
  {% endif %} 
  {% endif %}

 {% comment %} <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
  {% include 'dropdown-filter' %}
  </div>  {% endcomment %}
  <div id="product-loop">
    <div id="product_collection">
    {% for product in collection.products %}
    {% assign products-per-row = settings.products-per-row %}
   
    <div id="product-listing-{{ product.id }}" class="product_price product-index {% if products-per-row == "6" %}desktop-2{% elsif products-per-row == "4" %}desktop-3{% elsif products-per-row == "3" %}desktop-4{% elsif products-per-row == "5" %}desktop-fifth{% elsif products-per-row == "2" %}desktop-6{% endif %} tablet-half mobile-half" data-alpha="{{ product.title }}" data-price="{{ product.price | money_without_currency }}">          
      {% include 'product-listing' %}
    </div>
    {% endfor %}
    </div>
  </div>
</div>
{% include 'pagination' %}
{% endpaginate %}

{% endif %}


<script>

 $( document ).ready(function() {
 
    (function($){
      function fixButtonHeights() {
        var heights = new Array();

        // Loop to get all element heights
        $('.product-index').each(function() {
         
          // Need to let sizes be whatever they want so no overflow on resize
          $(this).css('min-height', '0');
          $(this).css('max-height', 'none');
          $(this).css('height', 'auto');
         
          // Then add size (no units) to array
          heights.push($(this).height());
        
//         alert(heights);
        });

        // Find max height of all elements
        var max = Math.max.apply( Math, heights );
//         alert(max);

        // Set all heights to max height
        $('.product-index').each(function() {
        
          $(this).css('height', max + 'px');
          // Note: IF box-sizing is border-box, would need to manually add border
               

        });
      }

      $(window).load(function() {
        // Fix heights on page load
        setTimeout(function() {
        fixButtonHeights();
        }, 3000);
        // Fix heights on window resize
        $(window).resize(function() {
          // Needs to be a timeout function so it doesn't fire every ms of resize
          setTimeout(function() {
            fixButtonHeights();
          }, 100);
        });
      });
    })(jQuery);
     
  });
 
</script>
<style>
 
</style>
<script>

</script>
<!-- <script>
  $(document).ready(function () {
    size_li = $("#myList li").size();
    x=40;
    $('#myList li:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+40 <= size_li) ? x+40 : size_li;
      if(x == size_li || x >= size_li){
        $('#loadMore').hide();
      }
        $('#myList li:lt('+x+')').show();
    });
});
</script> -->