Validating meta title and meta description with jQuery

Would you like to auto-display validation hints when a meta_title field is longer than 55 chars and a meta_description field is longer than 155 chars?

Then you can use this package: jQuery Meta Title and Description Validation.

Setup
1. Have at least one input field named meta_title or meta_description

E.g.

<p>
<input type="text" name="meta_title" placeholder="Meta title">
</p>
<p>
<input type="text" name="meta_description" placeholder="Meta description">
</p>

2. Initialize by including jquery-meta-validation.js

<script type="text/javascript" src="js/jquery-meta-validation.js"></script>


Laravel 5 Admin Middleware (is_admin user check)

Would you like to have middleware that makes sure that only users with an is_admin = 1 status will be able to see the admin section? Then you can use the following code:

app/Http/Middleware/AdminMiddleware.php

<?php

namespace App\Http\Middleware;

use Closure;

class AdminMiddleware
{

    /**
     * Handle an incoming request. User must be logged in to do admin check
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (\Auth::user()->is_admin == 1)
        {
            return $next($request);
        }

        return redirect()->guest('/');
    }
}

Make sure you’ll register the middleware as a route in app/Http/Kernel.php

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'admin' => \App\Http\Middleware\AdminMiddleware::class
];

Finally assign this middleware in the routes.php next to the auth middleware, since the admin middleware is an extension to the auth middleware.

App/Http/routes.php

Route::group(['prefix' => 'administration', 'middleware' => ['auth', 'admin']], function()
{
	Route::get('/', 'Admin\HomeController@index');
}

If you’ve suggestions to make this coding more efficient, you’re always welcome to drop a comment below.



SSH import sql database with host syntax (if not localhost)

How to import a .sql.gz file when the host is not localhost? Use this syntax:

$ mysql -h db365838511.db.1and1.com -u dbun1234 -p db365838511 &lt; 1and1help.com-Joomla-Apr.05.2010.sql

Explanation:

  • mysql: This is the MySQL command to access your databases
  • -h db365838511.db.1and1.com: This is the Host Name where your database is located (available from the 1&1 Control Panel).
  • -u dbun1234: This is the User Name for your database (available from the 1&1 Control Panel).
  • -p: This is to prompt for a password. Do not type the password now. You will be asked for the password after you hit ENTER.
  • db111111111: This is the database name.
  • < : This is to specify a database file should be imported to the database.
  • 1and1help.com-Joomla-Apr.05.2010.sql: This is the filename you will enter to specify which of the files you wish to import.

Source: 1and1



Magento Show Poll Results

Add this code in order to show the poll results in de poll block (using this article):

In addition for the result add in poll.phtml:

if ($poll-&gt;isVoted($poll-&gt;getId()) == TRUE) {
//Template Block
echo $this-&gt;getLayout()-&gt;createBlock(‘core/template’)-&gt;setTemplate(‘poll/result.phtml’)-&gt;setAttribute(‘my_poll_id’, $poll-&gt;getId())-&gt;toHtml();
} else {

// add the rest of the poll script here

}

Further open results.phtml and add on top:

if(!isset($poll)) {
$poll = new Mage_Poll_Model_Poll();
$poll-&gt;load($this-&gt;my_poll_id);

$action = Mage::getUrl(‘poll/vote/add’, array(‘poll_id’ =&gt; $poll-&gt;getId()));

$poll_answers = Mage::getModel(‘poll/poll_answer’)
-&gt;getResourceCollection()
-&gt;addPollFilter($poll-&gt;getId())
-&gt;load()
-&gt;countPercent($poll);

}

This should do the trick!


Lesti::Fpc and Layered Navigation

Lesti::Fpc is a great free Full Page Cache plugin for Magento. Though, it could be that it doesn’t work with Layered Navigation.

Solution

1. Go to your site and layered navigation and hover with your mouse on a filter item. It shows the url parameters (like ?color=red&manufacturer=brand).

2. Those parameter you need to add in the admin > config > system > Lesti::FPC > URL params. There add all the possible parameters from above. Like:

price,
cat,
manufacturer,
no_cache,
color

 



Magento import multiple images in dataflow csv/xml

Sometimes it’s really annoying that Magento only supports one image per product. On the Magento Commerce forum a solution is found:

Now, what you need to do is open the file
app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php
and go to around line 773 and find

$addedFilesCorrespondence = $mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
$product,
$arrayToMassAdd, Mage::getBaseDir('media') . DS . 'import',
false,
false
);

and paste the following code right after it
if (isset($importData['media_gallery']) && !empty($importData['media_gallery'])) {
$x = explode(',', $importData['media_gallery']);
foreach ($x as $file) {
$imagesToAdd[] = array('file' => trim($file));
}
$mediaGalleryBackendModel->addImagesWithDifferentMediaAttributes(
$product,
$imagesToAdd, Mage::getBaseDir('media') . DS . 'import',
false,
false
);
}

Source: http://www.magentocommerce.com/boards/viewthread/224928/P45/



Magento place order slow [FIXED]

The Magento “place order” step can take up to a minute. With thanks to this site I figured out how to fix slow checkouts.

Step 1

Find the file app/code/core/Mage/Rss/etc/config.xml and uncomment/remove:

<sales_order_save_after>
<observers>
<notifystock>
<class>rss/observer</class>
<method>salesOrderItemSaveAfterNotifyStock</method>
</notifystock>
</observers>
</sales_order_save_after>
<sales_order_save_after>
<observers>
<ordernew>
<class>rss/observer</class>
<method>salesOrderItemSaveAfterOrderNew</method>
</ordernew>
</observers>
</sales_order_save_after>

Step 2

Find the file app/code/core/Mage/Downloadable/etc/config.xml and uncomment/remove:

<!–sales_order_item_save_commit_after>
<observers>
<downloadable_observer>
<class>downloadable/observer</class>
<method>saveDownloadableOrderItem</method>
</downloadable_observer>
</observers>
</sales_order_item_save_commit_after–>



sqlstate 23000 integrity constraint violation 1048 column ‘value’ cannot be null magento

How to solve the problem ‘sqlstate 23000 integrity constraint violation 1048 column ‘value’ cannot be null magento’?

This problem is quite hard to identificate, because it’s hard to seek the right column ‘value’. Here is what I did in order to find out the problem.

  • Start the import process and see on which record number the errors occur.
  • Locate these record numbers and find the difference between other records in a spreadsheet program.
  • In my example I found out that on some rows the meta_robots column was empty instead of INDEX, FOLLOW. This caused the error.
  • Fill these rows. This will solve the problem.



BTW verhoging 21 procent doorvoeren in Magento (dutch)

Het kan de meeste mensen inmiddels niet ontgaan zijn, per 1 oktober 2012 zal er een BTW verhoging ingaan van 19 naar 21 procent. Vervelend daarbij is dat er nogal wat onduidelijkheden zijn. Aangezien ik zelf verstand heb van het webwinkel pakket Magento, probeer ik in dit artikel alle onduidelijkheden omtrent het nieuwe BTW tarief de wereld uit te helpen. U kunt daarbij zelf kiezen of u de BTW in de prijs door wilt voeren liever niet.

Stap 1: BTW tarief verhogen

Dit kunt u doen bij Verkopen > BTW > Beheer Belastingzones en Tarieven

Stap 2a: BTW in de prijs door laten voeren (prijsverhoging)

Hier komt een technisch verhaal bij kijken. De bedoeling is dat de catalogusprijs met de stijging van het btw-niveau automatisch meegaat. Uitgerekend is dit een prijsstijging van 1,68% (aan de hand van (1/119)*121*100% ). De bedoeling is dus om een negatieve korting te geven op alle producten.

Magento accepteert echter standaard geen negatieve kortingen:

Magento Negatieve Korting

 

 

Conform het volgende artikel moeten we dus een paar wijzigingen doorvoeren in de kern:

  1. Ga naar: app/code/core/Mage/Rule/Model/Rule.php en vind:
    //check if discount amount > 0
    if ((int)$this->getDiscountAmount() < 0) { 3 Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount amount.’));
    }
  2. Vervang deze code door deze uit te 'commenten':
    // if ((int)$this->getDiscountAmount() < 0) { 3 //Mage::throwException(Mage::helper(‘rule’)->__(‘Invalid discount //amount.’));
    //}
  3. Ga nu naar: app/code/core/Mage/Adminhtml/Block/Promo/Quote/Edit/Tab/Actions.php en vind: 'class' => 'validate-not-negative-number',
  4. ‘Comment’ deze code ook uit: // 'class' => 'validate-not-negative-number',
  5. Herhaal stap 3 en 4 voor het bestand app/code/core/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Actions.php
  6. Verander in het bestand app/code/local/Mage/CatalogRule/Model/Observer.php :
    $finalPrice = min($product->getData(‘final_price’), $this->_rulePrices[$key]);
    in:
    $finalPrice = $this->_rulePrices[$key];
  7. Vervolgens kunt u deze bestanden uploaden (het veiligste is om de bestanden niet in app/code/core, maar app/code/local op te slaan).
Vervolgens kunt u de negatieve korting doorvoeren.
Ga naar promotie > catalogus prijsregels > nieuwe regel aanmaken. Geef de prijsregel een naam en voer bij actie het tarief van -1,68 procent in. Daarbij kunt u een vanaf datum van 1 oktober 2012 instellen. Vervolgens kunt u de wijzigingen opslaan en klikt u op ‘apply rules’.
Het nadeel van een automatische stijging is wel dat een ‘mooie’ prijs als €49,95 zal vanderen in €55,21. Mocht u later dus alle prijzen handmatig wijzigen, kunt u de zojuist ingevoerde prijsregel weer uitzetten.

Stap 2b: BTW niet in de prijs door laten voeren (gelijke prijs)

Als het goed is, is hier verder geen wijziging voor nodig.