Loading

Author Topic: Automatic premium ads?  (Read 804 times)

sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Automatic premium ads?
« on: February 02, 2012, 10:57:50 pm »
Hi!

I want to make the ads with free items (price=0) automatically premium ads. Is this possible?

Thanks,
Stefan


Swede

  • Super Moderator
  • Sr. Member
  • *****
  • Posts: 381
Re: Automatic premium ads?
« Reply #1 on: February 03, 2012, 12:55:58 am »
I get your point... this would be a nice feature to be able to list all the free stuff automaticly!

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 1922
Re: Automatic premium ads?
« Reply #2 on: February 03, 2012, 11:39:48 am »
Hi sstef25,


A plugin for that is not very difficult to do. Did you try to do it by yourself?


Thanks

sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #3 on: February 03, 2012, 12:56:19 pm »
Hi _CONEJO,

I have to admit i didn't try it, i'm not really a programmer, i have very little knowledge of php, but i will try it somehow.... a little help&guidence would be apreciated though :D

I've read about how to do a plugin, but i'm not sure about the actual code ...
I think basically, after the item is activated, i have to do an if-then-else statement checking the price and setting the premium attribute accordingly  ??? ...


Thanks,
Stefan

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 1922
Re: Automatic premium ads?
« Reply #4 on: February 03, 2012, 01:53:34 pm »

For the plugin, I did not test it, but it should work (at least it's an starting point). Create a folder called "autopremium" in oc-content/plugins, create a file called index.php on that folder, a nd paste this code :


<?php
/*
Plugin Name: Auto premium
Plugin URI: http://www.osclass.org/
Description: This plugin makes premium ads those without price
Version: 0.1
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: autopremium
Plugin update URI: 
*/

    
function autopremium_post($catId null$item_id null)  {
        
$item Item::newInstance()->findByPrimaryKey($item_id);
        if(
$item['i_price']==null || $item['i_price']==0) {
            
Item::newInstance()->update(array('b_premium' => 1), array('pk_i_id' => $item_id));
        } else {
            
Item::newInstance()->update(array('b_premium' => 0), array('pk_i_id' => $item_id));
        }
    }
    
    
// This is needed in order to be able to activate the plugin
    
osc_register_plugin(osc_plugin_path(__FILE__), '');
    
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
    
osc_add_hook(osc_plugin_path(__FILE__). '_uninstall''');

    
osc_add_hook('item_form_post''autopremium_post');
    
osc_add_hook('item_edit_post''autopremium_post');

?>

sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #5 on: February 03, 2012, 02:33:09 pm »
Hi _CONEJO!

Thanks a lot, it's seem to be working just fine!!

 I have 2 quick question though: :)

1. changing  this
Code: [Select]
if($item['i_price']==null || $item['i_price']==0) { to this 
Code: [Select]
if($item['i_price']==0) { shouldn't make premium just the ads with price 0, not those with nothing at price (the "check with seller") ads?

2. i'm using the posterious plugin (http://forums.osclass.org/plugins/posterous-plugin-autopost-premium-ads-to-posterous-facebook-etc/) wich was working fine for me, but this autopremium ads are not "processed" by this plugin, i was wondering why? i see posterous plugin uses item_premium_on hook ... maybe it's not triggered or something?

Thanks,
Stefan

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 1922
Re: Automatic premium ads?
« Reply #6 on: February 03, 2012, 02:36:28 pm »
Try with this:

<?php
/*
Plugin Name: Auto premium
Plugin URI: http://www.osclass.org/
Description: This plugin makes premium ads those without price
Version: 0.1
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: autopremium
Plugin update URI: 
*/

    
function autopremium_post($catId null$item_id null)  {
        
$item Item::newInstance()->findByPrimaryKey($item_id);
        if(
$item['i_price']==null || $item['i_price']==0) {
            
ItemActions::newInstance()->premium($item_id1);
        } else {
            
ItemActions::newInstance()->premium($item_id0);
        }
    }
    
    
// This is needed in order to be able to activate the plugin
    
osc_register_plugin(osc_plugin_path(__FILE__), '');
    
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
    
osc_add_hook(osc_plugin_path(__FILE__). '_uninstall''');

    
osc_add_hook('item_form_post''autopremium_post');
    
osc_add_hook('item_edit_post''autopremium_post');

?>



That should make both plugins work if i'm not wrong ;)

sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #7 on: February 03, 2012, 02:43:53 pm »
Oops,
now i got this:

Fatal error: Call to undefined method ItemActions::newInstance() in /home/bazarulc/public_html/oc-content/plugins/autopremium/index.php on line 16

Stefan

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 1922
Re: Automatic premium ads?
« Reply #8 on: February 03, 2012, 02:48:52 pm »

Try with this:

<?php
/*
Plugin Name: Auto premium
Plugin URI: http://www.osclass.org/
Description: This plugin makes premium ads those without price
Version: 0.1
Author: OSClass
Author URI: http://www.osclass.org/
Short Name: autopremium
Plugin update URI: 
*/

    
function autopremium_post($catId null$item_id null)  {
        
$item Item::newInstance()->findByPrimaryKey($item_id);
        if(
$item['i_price']==null || $item['i_price']==0) {
            
$mItems = new ItemActions(true);
            
$mItems->premium($item_id1);
        } else {
            
$mItems = new ItemActions(true);
            
$mItems->premium($item_id0);
        }
    }
    
    
// This is needed in order to be able to activate the plugin
    
osc_register_plugin(osc_plugin_path(__FILE__), '');
    
// This is a hack to show a Uninstall link at plugins table (you could also use some other hook to show a custom option panel)
    
osc_add_hook(osc_plugin_path(__FILE__). '_uninstall''');

    
osc_add_hook('item_form_post''autopremium_post');
    
osc_add_hook('item_edit_post''autopremium_post');

?>


sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #9 on: February 03, 2012, 02:57:26 pm »
Hey, this is it! :)

Now both plugins are working! :D Thanks!!

So how to do to make premium just the ads with price=o (free), not those with price empty ("check with seller")
I deleted
Quote
$item['i_price']==null ||
but nothing seems to happen  :o

Stefan


sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #10 on: February 04, 2012, 08:34:47 pm »
Hi _CONEJO,

How to do to make premium only the ads with price=0?
I used this
Code: [Select]
if($item['i_price']==0) { but nothing changes.... it still makes premium also the ads with nothing at price (check with seller)... am i missing something?

Thanks,
Stefan

trains58554

  • Super Moderator
  • Hero Member
  • *****
  • Posts: 1821
  • The Ghostbuster
Re: Automatic premium ads?
« Reply #11 on: February 04, 2012, 08:48:13 pm »
Hi sstef25,

Try this


 
if($item['i_price'] != null && $item['i_price'] == 0) {


Jay
« Last Edit: February 04, 2012, 08:50:08 pm by trains58554 »

sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #12 on: February 04, 2012, 09:55:06 pm »
Hi Jay,

Thanks, seems to work ok now.... should have thought myself to that but i was sure it only need equal with 0 operator and thought the problem was elsewhere :D

Thanks,
Stefan

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 1922
Re: Automatic premium ads?
« Reply #13 on: February 06, 2012, 11:59:20 am »
Hi sstef25


In most cases "0" is equal to "false" (and null as it seems to be the case here). If you want to check when is EXACTLY 0 or exactly any other case, we need to use the === (yes, three =) operator.

if($item['i_price']===0) {
That should work (but again, I didn't test it).


This is useful for function like strpos/stripos (which return the position of a string inside another string) being 0 the first position and false is the string is not found.

sstef25

  • Jr. Member
  • **
  • Posts: 68
    • Email
Re: Automatic premium ads?
« Reply #14 on: February 06, 2012, 10:47:36 pm »
Hi _CONEJO,

Thanks, i didn't know that, i will try it! Anyway, Jay's solutions is working...

Stefan