News:

Looking for documentation? Take a look on our wiki

Main Menu

Own Extension

Started by kiki90, August 22, 2012, 14:15:22 PM

Previous topic - Next topic

kiki90

Hiya !

I am currrently trying to develop a script where a cron setup calls a script and runs to get some data from another server and inputs them into the dB. Till then everything is fine but what I want really is something where the script doesn't actually call the database directly. I would rather use a method already in virtuemart for security reasons.

How do I go about implmenting this?

Thanks :)

ivus

Hi kiki90,

Not a VM issue. Your question is related to PHP and Joomla! directly.

The fact that you want to target already built VM model and function is negligible without first learning the functions of Joomla!, specific to extending/creating your own components.

You want to build a front end component for a CRON job to target (you can have a front end component without a back end component, and vice versa). Here's a good start so you're not waiting around for another 24 hours.

http://docs.joomla.org/Developing_a_Model-View-Controller_Component/2.5/Developing_a_Basic_Component

There's also this nifty little extension you can begin with.

http://extensions.joomla.org/extensions/administration/admin-performance/19490

Good luck. ;D

kiki90

#2
Hi

Thanks for your reply .. Well my component is already up and running and using the cron aswell .. but I am inserting these in a dummy table using INSERT INTO.

VirtueMarts' API didn't help me at all ... that's why I posted here.

EDIT:: Oh and btw that's what I'm using to run cron :P

ivus

Hi kiki90,

Well your original post is too vague.

I still don't know what your problem or issue is?

Now you're aware that JPrc Cron is not a real cron scheduler? it's a cron simulator.

kiki90

Yes yes I know. That is infact what I need.

Sorry for my english, not my mother language and I'm not very good at explaining stuff but lemme try again.

I have a component that basically "downloads" my stock from our own server and lists them as table, not very neat isn't it? So we said, let's import them into virtuemart. I first ran the "cron" and downloaded the stock into a table (dummy) to see what type of code etc.

The problem lies here: It works fine using INSERT INTO and simple SQL but that's not very secure. What I would like to implement is use VirtueMarts' own methods to insert into the database...

ivus

Hi kiki90,

Quote
The problem lies here: It works fine using INSERT INTO and simple SQL but that's not very secure. What I would like to implement is use VirtueMarts' own methods to insert into the database...

You mean you write the query string in full? or you use Joomla! database object to form your queries? ie



$db = JFactory::getDbo();
$query = $db->getQuery(true);

$query->insert('#__database_table');
$query->set('column_1 = ' . $value);
$query->set('column_2 = 1');
$db->setQuery($query->__toString());
$db->query();



Because deep down in the VM core... this is how data gets entered into the DB also.




Anyway...

Do you know which functions you need to use? from which controller/model/helper?

You can start by putting this at the top of your pge before you define your class:



if (!class_exists ('VmConfig')) {
require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'config.php');
}
VmConfig::loadConfig ();

JFactory::getLanguage ()->load ('com_virtuemart');
if (!class_exists ('calculationHelper')) {
require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'calculationh.php');
}
if (!class_exists ('CurrencyDisplay')) {
require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'currencydisplay.php');
}
if (!class_exists ('VirtueMartModelVendor')) {
require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models' . DS . 'vendor.php');
}
if (!class_exists ('VmImage')) {
require(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'image.php');
}
if (!class_exists ('shopFunctionsF')) {
require(JPATH_SITE . DS . 'components' . DS . 'com_virtuemart' . DS . 'helpers' . DS . 'shopfunctionsf.php');
}
if (!class_exists ('calculationHelper')) {
require(JPATH_COMPONENT_SITE . DS . 'helpers' . DS . 'cart.php');
}
if (!class_exists ('VirtueMartModelProduct')) {
JLoader::import ('product', JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_virtuemart' . DS . 'models');
}



Obviously you'll need to tailor it to your exact requirement... but this should get you started.

The rest of the code can be found in front end components, modules, plugins etc... just have a look for them.


kiki90

Hey :)

First off - THANK YOU :D

This really helped and i'm on my way to finish it off... but is there a way to enter a url as an image?

My images are on a server ... Is it possible to show the images anyway ?

Thanks :)

ivus

Hi kiki90,

I'm not sure what you mean

Quotebut is there a way to enter a url as an image

Like, did you want to link an image to one that is on the server? In which case are you asking about full absolute URL to that resource?



$image_url = JURI::base() . 'images/etc/etc/' . $this->image;



Something like that?

kiki90

Yeah like

www.something.com/images/image.jpeg

for example.

Or else could I use something like this?

<div class="product-fields">
       <?php
       $custom_title 
null;
       foreach (
$this->product->customfieldsSorted[external] as $field) {
      if (
$field->display) {
          
?>

          <?php if ($field->custom_title != $custom_title) { ?>
            <img src="<?php echo $field->display ?>" alt="<?php echo $this->product->product_name ?>"  />
<?php ?>
          <?php ?> <?php ?>
        </div>


Create a custom field with type string?

kiki90

I downloaded the image on my localhost ... Is there a way to upload the image with the product? I discovered that he uses a $_FILES to upload the image.. and he gets the file name etc from the array the $_FILES produces

ivus

Hi kiki90,

Yes, that simply puts the files onto the server.

There are already built in functions to retrieve the images assigned to the product.


$product_model->addImages($product);


You're not clear about what it is you want to do.

kiki90

OK,

So I added a product to the database using the store function. Now I would like to add an image to that product. At first I wanted to add a url maybe... but that's inconvenient for me ..

So I thought ... If I managed to add a product using vms own functions I can easily add an image as well... So I downloaded the image to images/stories/virtuemart/products/

Then I started debugging to see if everything is working correctly, but the image wasn't being added correctly. The file title was being displayed but the image was a yellow exclamation mark.

So I debugged virtuemart itself and added an image as well to see how it works etc.. It uses $_FILES to add an image having an array with the name size temp name etc.

The file name is derived from that array ..

So my problem is how can i skip the $_FILES thing as there is no upload involved in what i'm doing...

Hope I'm clear.

Sorry !

ivus

This is all being done from your CRON script? not the VM backend?

kiki90

Well my CRON script links to the VM functions to store the product. The only problem I'm having is that the VM uses $_FILES to upload the image to the store itself and links it to the product..

ivus