Richard Castera - Explorations in Software Development
Richard Castera - Explorations in Software Development
Browsing Category
Resources Scripts

Magento – Add a product with custom options to the cart through URL Querystring

August 2, 2009 21 Comments

Magento is truly a powerful and flexible platform! I enjoy working with it more and more every day. I recently came across the need to add a product to the cart VIA the Querystring/URL. Guess what? Magento can do it and I’ll show you how!

Simple products are the easiest to add because there are fewer options that need to be passed. The basic structure is as follows.

XHTML
1
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]

Where [id] is the Magento ID of the product and [qty] is the Quantity you wish to add.

To add a simple product with custom options simply add options[id]=[value] to the end. The basic structure is:

XHTML
1
http://www.mydomain.com/checkout/cart/add?product=[id]&qty=[qty]&options[id]=[value]

You can get the options id and value by viewing the source of the simple product page and it’s dropdowns.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

Using SSH and Unix commands

July 31, 2009 8 Comments

Having some basic knowledge of SSH and Unix commands is very useful. Developed in 1995, SSH (Secure Shell) was created as a secure alternative to Telnet. Telnet is a protocol allowing for command line access to a Unix, Linux or FreeBSD based remote computer. I’ve listed some basic commands to get you familiar with them.

The cd command is used to move to a specific directory.

Shell
1
2
Command: cd
Format: cd /directory/to/browse

The cp command will copy the file or folder from the source, to the destination.

Continue reading
Reading time: 2 min
Share:
Written by: rcastera
Resources Scripts

PHP – Convert Array to Object with stdClass

July 5, 2009 53 Comments

The PHP stdClass() is something that isn’t well documented but i will try to shed some light into the matter. stdClass is a default PHP object which has no predefined members. The name stdClass is used internally by Zend and is reserved. So that means that you cannot define a class named stdClass in your PHP code.

It can be used to manually instantiate generic objects which you can then set member variables for, this is useful for passing objects to other functions or methods which expect to take an object as an argument. An even more likely usage is casting an array to an object which takes each value in the array and adds it as a member variable with the name based on the key in the array.

Here’s an example below that converts an array to an object below. This method is called Type Casting.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Web Server

Migrating Magento to another server

June 29, 2009 22 Comments

Migrating your Magento website to another server is relatively a simple task once you know how to do it of course. I have detailed the steps on how to do this below so you can use this post as a point of reference 🙂

  1. From the admin, go to Configuration -> Web -> and change the (Unsecure and Secure) fields to {{base_url}}.
  2. From the admin, go to System -> Tools -> Backups and click on the backup button. This will create a backup of your database.
  3. Make a copy your Magento root.
  4. Move all data over to the new server.
  5. Restore the database on the new host.
  6. If you have a different username, password or database name. You’ll need to update that as well. You can find the file in (‘magento_root/app/etc/local.xml’) and make the required changes.
  7. Navigate to your Magento root, and delete all of the files and folders in, (i.e. /var/www/magento/var) except for the .htaccess file.

Hope this helps someone 🙂

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

PHP – getting a list of currently loaded classes

June 25, 2009 1 Comment

In some cases you may need to investigate which classes are loaded in the current scope. You can do it pretty fine with the get_declared_classes() function. This function will return an array of currently available classes.

PHP
1
2
3
4
<?php
    include_once("class.myClass.php");
    print_r(get_declared_classes());
?>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Add Magento search plugin to Firefox Search bar

June 24, 2009 2 Comments

I’ve been working with Magento for some time now. I found myself searching for help countless times on the Magento website. I thought it would be useful to have a search feature built right into Firefox’s list of search engines to search the Magento site. So I went through Mozilla’s Developer Center and found instructions on the Open Search Syntax. So here you go, you can download it here. Hope you find it helpful!

I also have one for PHP which comes in handy as well. If your interested, you can grab it here.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

Javascript – Passing Multiple Parameters through setTimeout

June 21, 2009 13 Comments

One of the problems that I’ve faced with Javascript is passing multiple parameters through the setTimeout function. I found this little snippet on the internet a few months ago and would like to share it with you. I don’t know who the original author is so I could not give him/her proper credit. Thanks!

JavaScript
1
2
3
4
5
6
7
8
9
10
11
12
<script>
var _st = window.setTimeout;
window.setTimeout = function (fRef, mDelay) {
    if (typeof fRef == "function") {
        var argu = Array.prototype.slice.call(arguments,2);
        var f = (function () {fRef.apply(null, argu);});
        return _st(f, mDelay);
    }
    return _st(fRef, mDelay);
}
</script>

Define your function to call with setTimeout:

JavaScript
1
2
3
4
5
<script>
function alertMe (message, name) {
    alert(message + name);
}
</script>

Now, just call the function.

JavaScript
1
2
3
var message = 'Hello, ';
var name = 'Richard';
setTimeout(alertMe, 2000, message, name);

Hope this helps someone! 🙂

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts

How to define your own JavaScript class

June 7, 2009 8 Comments

There are several ways to define a class in Javascript. I will be listing my favorite method below (JSON Method). It’s important to note that there are no real classes in JavaScript. Everything is considered an object. So below is our class definition:

JavaScript
1
2
3
4
5
6
7
8
9
10
<script>
var Person = {
    age: "25",
    sex: "Male",
    location: "New York",
    getASL: function () {
        return 'Age: ' + this.age + ', Sex: ' + this.sex + ', Location: ' + this.location;
    }
};
</script>

So you can start using the class like this:

JavaScript
1
2
3
4
<script>
Person.age = "29";
alert(Person.getASL());
<script>
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Thoughts

Magento Beginners Guide – A great book for any Magento Store Owner

June 1, 2009 1 Comment

Recently I obtained a copy of Magento Beginner’s Guide by William Rice from Packt Publishing. This book is great, I would recommend it to any new or existing Magento store owner. It servers as an excellent reference guide for experienced users and a great beginners guide for new store owners.

Magento is the world’s most evolved e-commerce solution and runs on the Apache/MySQL/PHP platform. From one installation, users can control multiple storefronts, all sharing customer and product information. Magento’s templates and themes enable users to customize the look and feel of their store, even optimizing it for mobile phones. Extensions enable them to connect Magento to a large number of payment gateways and shipping services.

Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Resources Scripts Web Server

.htaccess – Limit website access by IP

May 31, 2009 4 Comments

I’ve been asked many times how to limit website access by allowable IP’s. This is fairly simple to accomplish with .htaccess and very useful for blocking web vagrants to allowing you to make updates to a website while redirecting all other IP’s to a maintenance page. Simply follow the steps below:

  1. Create a file and name it .htaccess.
  2. Add The following to the file:
    Apache
    1
    2
    3
    order deny,allow
    deny from all
    allow from 255.255.255.255
  3. Replace 255.255.255.255 with you IP address. (If you don’t know it, you can get it here: WhatsMyIP)
  4. Once the file is created, put it in the root directory. That’s it!
Continue reading
Reading time: 1 min
Share:
Written by: rcastera
Page 6 of 11« First...«5678»10...Last »

About me

Hello, my name is Richard Castera. I have more than 12 years of experience architecting, implementing, leading and launching large scale, high performance software products in a fast-paced agile environment.

Popular Posts

Magento – Display new products on the home page

May 20, 2009

How to Fix “Internet Explorer Cannot Open the Internet Site- Operation Aborted” Error

May 9, 2009

PHP – Convert Array to Object with stdClass

July 5, 2009

Categories

  • Home Automation
  • Resources
  • Scripts
  • SEO
  • Thoughts
  • Web Server

Tags

Apache Apple Bash CSS Drupal Free home automation htaccess Java Javascript Magento PHP raspberry pi SEO SQL thoughts Wordpress

© 2019 copyright Richard Castera // All rights reserved