logo-mini

معرفی vQmod و ساختار و روش ایجاد آن برای OPENCART

به اشتراک گذاری این پست

معرفی vQmod و ساختار و روش ایجاد آن برای OPENCART

فروشگاه ساز اوپن کارت جزو بهترین نرم افزارهای ساخت فروشگاه اینترنتی با مقیاس کوچک تا بزرگ میباشد.  سال ۱۳۸۸ با دوستان خوبم همچون نیما.الف و فرشید.عین نمایندگی رسمی این فروشگاه ساز را برای اولین بار در ایران گرفتیم و به دلیل تحریم ها و… کلا ایران از سیستم حذف گردید!!

البته اون موقع مارکت ساز باعث معرفی این سیستم به ایرانیان عزیز شده بود و همچنان هم هست!!

توسعه opencart بسیار طاقت فرسا و سخت هست و vqmod همچون معجزه …جلوی مرگ این نرم افزار را گرفت….بصورتی که شما به جای تغییر در ۱۰۰۰ خط و ویرایش فایل ها با ساختار MVC ….کل تغییرات خود را در یک فایل XML ذخیره میکنید و خود سیستم همه کارها را برایتان انجام میدهد!!!

یعنی کدهای opencart ابتدا از فیلتر vqmod عبور کرده همراه با کدهای شما مخلوط میشود و در پایان اجرا میشود….با vqmod هر کاری…هر کاری!!! را میتوان انجام داد!!!

……………………………در یک کلمه سیستم جایگزینی preg_replace…فانشن دوست داشتنیمون رو یادتون بیاد…دقیقا vqmod همینکارو براتون انجام میده……………

در ادامه مقاله ساخت فایل های vqmod را براتون میزارم… البته به زبان اصلی….هر چیزی باید به زبان اصلیش آموزش داده بشود!

OpenCart has been a successful framework for small-to-medium scale e-commerce sites. Although the core of OpenCart provides many features a shopping cart site needs in the front-end, it’s also the third-party extensions that play a major role in its success.

Having said that, circumstances may arise in which you’ll be forced to change the core of OpenCart. In this tutorial, we’ll see how you can alter the core of the OpenCart using the vQmod extension.

vQmod is a popular extension that allows you to make changes without actually modifying core files. This is the excerpt from the official vQmod site.

“vQmod™” (aka Virtual Quick Mod) is an override system designed to avoid having to change core files. The concept is quite simple… Instead of making changes to the core files directly, the changes are created as xml search/replace script files. These script files are parsed during page load as each “source” core file is loaded with the “include” or “require” php functions. The source is then patched with the script file changes, and saved to a temp file. That temp file is then substituted for the original during execution. The original source file is never altered. This results in a “virtual” change to the core during execution without any actual modification to the core files.

So it’s really useful in the way that it makes the upgrade process of OpenCart smooth even if you’ve altered the core files.

Before we go ahead and learn how to use vQmod with OpenCart, let’s see how exactly vQmod works.

vQmod does all its magic using XML files. You need to create an XML file as per the conventions, and the rest of the functionality will be handled by vQmod. With that said, let’s see how exactly the XML file should look.

This is a simple demonstration that shows how you could replace a certain piece of code in the file with other content.

As you can see, it starts with the standard <?xml> tag declaration followed by a<modification> tag. Other tags include <id>, <version>, and <author>. You should not change <vqmver> as it indicates the vQmod version.

The interesting work starts with the <file> tag. The name attribute indicates the file name that will be patched. It could be that you need multiple modifications to the same file. So that’s where the <operation> tag comes into play. Each modification will be wrapped by the <operation> tag. The info attribute allows you to add some useful message.

In this particular example, the <search> tag is used for the replace operation. You can use the position attribute to tell vQmod which operation will be performed. The content which is enclosed inside the <search> tag will be replaced with the content which is enclosed within the <add> tag.

As you may have noticed, the content for search and replace is enclosed within a CDATA tag, which means that the content won’t be interpreted as a markup but as character data.

Let’s see the other options available for the position attribute:

  • before is used to insert the content before the search string.
  • after is used to insert the content after the search string.
  • top is used to insert the data at the top of the file. In this case, there’s no need for the <search> tag. Even if you’ve used it, it’ll be ignored.
  • bottom is used to insert the data at the bottom of the file. In this case, there’s no need for the <search> tag. Even if you’ve used it, it’ll be ignored.
  • In the case of ibefore, the data will be appended before the search data in the same line.
  • In the case of iafter, the data will be appended after the search data in the same line.

There are also a couple of optional attributes available for the <search> tag. Let’s have a quick look at these.

  • offset is an attribute designed to work in conjunction with the position attribute. So, for example, if position is set to before andoffset is set to 3, it means that the content will be inserted before the three lines of the searched data.
  • index: Sometimes you want to replace only couple of instances of a particular string, not all the instances of that string in the search data. Say, for example, there are five instances of the $abc variable in your search data, but you only want to replace the first two instances of $abc with $def. In this case you need to specify index to 1,2.
  • The regex attribute is useful if you want to perform a regular expression based search for your operations. In that case, you’ll need to set regex toTRUE.

These are the quick highlights of vQmod’s configuration options.

Let’s take a look at how we can install the vQmod OpenCart extension. We’ll also review how you could use vQmod to alter the core of OpenCart.

  • Download and extract the OpenCart-specific vQmod library.
  • Upload the vqmod directory to the root of your OpenCart installation.
  • Please make sure the vqcache directory that is under the vqmod directory is writable by the web server.
  • Visit http://www.myopencartsite.com/vqmod/install and you should be presented with a success message. If that’s not the case, it’s likely a permissions issue.

Now you’re ready to use any vQmod-specific extension, or create your own.

Now that you’re armed with all the weapons, let’s go through a practical example. Create an XML file vqmod_homepage.xml in the vqmod/xml directory. Copy and paste the following contents in the newly created vqmod_homepage.xml file.

Now open your homepage and you should see that there is an <h1> title that is displayed. By default, it’s “Your Store”. All the files inside the vqmod/xml directory are detected automatically and the changes are applied accordingly. You could find the cached version of the files under vqmod/vqcache.

It’s pretty straightforward if you look at the vqmod_homepage.xml file. We’re using a replace operation on the home.tpl file. An important thing to note is that the path of the file is given relative to the vqmod directory.

 http://www.opencart.com/index.php?route=extension/extension/info&extension_id=2969

محمدرضا

محمدرضا محمودی هستم ، سعی شده در این وبلاگ مطالب مفید و کارامدی قرار بگیره ، از اینکه وقت میگذارید و مطالب رو مطالعه میکنید متشکرم... ممنون میشم اگر موردی و یا ... میبینید حتما نظرات خودتون رو ارسال کنید


نظر بدهید