Advertisement:

Author Topic: SOLVED ad posting - only for company  (Read 2333 times)

andrei2987

  • Newbie
  • *
  • Posts: 40
SOLVED ad posting - only for company
« on: July 07, 2017, 11:38:52 pm »
hi,

i have this code:

Code: [Select]
<ul class="nav">
            <?php if( osc_users_enabled() ) { ?>
<?php if( osc_is_web_user_logged_in() ) { ?>
            <?php if( osc_users_enabled() || ( !osc_users_enabled() && !osc_reg_user_post() )) { ?>

            <li><a class="publish-btn" href="<?php echo osc_item_post_url() ; ?> <?php _e("New AD"'theme');?></a></li>

            <?php ?>

             <li class="dropdown profilepic">
                <a class="dropdown-toggle" data-toggle="dropdown" href="">
                <?php echo osc_logged_user_name(); ?></a>
                    <ul class="dropdown-menu">
                        <li><a href="<?php echo osc_user_dashboard_url(); ?>"><?php _e('My account''theme'); ?></a></li>
                        <li><a href="<?php echo osc_user_list_items_url(); ?>"><?php _e('My ads''theme'); ?></a></li>
                        <li><a href="<?php echo osc_user_logout_url(); ?>"><?php _e('Logout''theme'); ?></a></li>
                    </ul>
                </li>

            <?php } else { ?>
                <li><a href="<?php echo osc_user_login_url(); ?>"><?php _e('Log in''theme') ; ?></a></li>
            <?php ?>
            <?php ?>
          </ul>

what i whant to do is:
this line of code (whit New AD button)
<li><a class="publish-btn" href="<?php echo osc_item_post_url() ; ?>"> <?php _e("New AD", 'theme');?></a></li>
show only if account is company

i think something like this:
$user = User::newInstance()->fiindByPrimaryKey($id);
if($user['b_company']==1) {
//IT IS A COMPANY
} else {
// IT IS A PRIVATE USER
}

but i don't know how to use it in my code.

thanks
« Last Edit: August 01, 2017, 04:33:56 pm by andrei2987 »

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: ad posting - only for company
« Reply #1 on: July 08, 2017, 12:29:17 am »
try this...

Code: [Select]
<?php if (osc_user_is_company() == '1') { ?>
<li><a class="publish-btn" href="<?php echo osc_item_post_url() ; ?>"> <?php _e("New AD"'theme');?></a></li>
<?php ?>


or replace your whole posted code with this
Code: [Select]

<ul class="nav">
    <?php if( osc_users_enabled() ) { ?>
    <?php if( osc_is_web_user_logged_in() ) { ?>
    <?php if (osc_user_is_company() == '1' && (osc_users_enabled() || (!osc_users_enabled() && !osc_reg_user_post()))) { ?>
    <li><a class="publish-btn" href="<?php echo osc_item_post_url() ; ?>"> <?php _e("New AD"'theme');?></a></li>
    <?php ?>
    <li class="dropdown profilepic">
    <a class="dropdown-toggle" data-toggle="dropdown" href="">
    <?php echo osc_logged_user_name(); ?></a>
    <ul class="dropdown-menu">
    <li><a href="<?php echo osc_user_dashboard_url(); ?>"><?php _e('My account''theme'); ?></a></li>
    <li><a href="<?php echo osc_user_list_items_url(); ?>"><?php _e('My ads''theme'); ?></a></li>
    <li><a href="<?php echo osc_user_logout_url(); ?>"><?php _e('Logout''theme'); ?></a></li>
    </ul>
    </li>
    <?php } else { ?>
    <li><a href="<?php echo osc_user_login_url(); ?>"><?php _e('Log in''theme') ; ?></a></li>
    <?php ?>
    <?php ?>
</ul>


« Last Edit: July 08, 2017, 12:34:26 am by Liath »

andrei2987

  • Newbie
  • *
  • Posts: 40
Re: ad posting - only for company
« Reply #2 on: July 08, 2017, 10:11:44 am »
it works,

many thanks Liath

andrei2987

  • Newbie
  • *
  • Posts: 40
Re: ad posting - only for company
« Reply #3 on: July 08, 2017, 12:12:44 pm »
hi Liath,

do you know why is work fine only on pages: mysite.com/user/profile, mysite.com/user/items, mysite.com/user/alerts  ...all with /user/ ... ?

and for other pages not work.

thx

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: ad posting - only for company
« Reply #4 on: July 26, 2017, 09:00:16 pm »
In which file did you make those modifications?

andrei2987

  • Newbie
  • *
  • Posts: 40
Re: ad posting - only for company
« Reply #5 on: July 26, 2017, 09:23:59 pm »
In which file did you make those modifications?

in header.php

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: ad posting - only for company
« Reply #6 on: July 26, 2017, 09:28:45 pm »
Did you use the first or second block of code?


Second code:

Code: [Select]
<?php if( osc_users_enabled() ) { ?>
    <?php if( osc_is_web_user_logged_in() ) { ?>
    <?php if (osc_user_is_company() == '1'


......

andrei2987

  • Newbie
  • *
  • Posts: 40
Re: ad posting - only for company
« Reply #7 on: July 26, 2017, 10:03:29 pm »
I used second block..

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: ad posting - only for company
« Reply #8 on: July 26, 2017, 10:22:34 pm »
Try this

Code: [Select]

<ul class="nav">
   <?php if( osc_users_enabled() ) { 
    if( osc_is_web_user_logged_in() ) {
                   if(
osc_user_is_company()) { ?>

                        <li><a class="publish-btn" href="<?php echo osc_item_post_url() ; ?> <?php _e("New AD"'theme');?></a></li>
                   <?php } else { ?>
                         <li><a class="publish-btn" >You are not a company</a></li>
                   <?php ?>

             <li class="dropdown profilepic">
                <a class="dropdown-toggle" data-toggle="dropdown" href="">
                <?php echo osc_logged_user_name(); ?></a>
                    <ul class="dropdown-menu">
                        <li><a href="<?php echo osc_user_dashboard_url(); ?>"><?php _e('My account''theme'); ?></a></li>
                        <li><a href="<?php echo osc_user_list_items_url(); ?>"><?php _e('My ads''theme'); ?></a></li>
                        <li><a href="<?php echo osc_user_logout_url(); ?>"><?php _e('Logout''theme'); ?></a></li>
                    </ul>
                </li>

            <?php } else { ?>
                <li><a href="<?php echo osc_user_login_url(); ?>"><?php _e('Log in''theme') ; ?></a></li>
            <?php ?>
            <?php ?>


« Last Edit: July 26, 2017, 10:55:12 pm by marius-ciclistu »

andrei2987

  • Newbie
  • *
  • Posts: 40
Re: ad posting - only for company
« Reply #9 on: July 27, 2017, 03:40:24 pm »
hi marius,

is not working in all pages.

if URL is mysite.com/user/profile, mysite.com/user/items, mysite.com/user/alerts  ...all with /user/  -- work fine (show Ad button)

in other pages (homepage, search, etc)--not work (show "You are not a company") and hide Ad button

ps. user type is "Company" in this test



marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: ad posting - only for company
« Reply #10 on: July 27, 2017, 05:35:27 pm »
Liath, is osc_user_is_company() not wotking in the non-user pages?

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: ad posting - only for company
« Reply #11 on: July 27, 2017, 08:16:03 pm »
As Liath said here maybe it will work in a similar way:
https://forums.osclass.org/development/countitemtypesbyuserid(osc_logged_user_id()-active)-not-working/msg152820/#msg152820

So try to replace

osc_user_is_company()

with

User::newInstance()->osc_user_is_company()

Liath

  • issues
  • Hero Member
  • *
  • Posts: 1346
  • </html> the end is always near
Re: ad posting - only for company
« Reply #12 on: July 28, 2017, 03:01:13 am »
Maybe the User View is not loaded on item pages...


you could try this on other pages
Code: [Select]
<?php
$seller 
User::newInstance()->findByPrimaryKey(osc_item_user_id());
if (
$seller['b_company'] == '1') {
    ...
}
?>


instead of
Code: [Select]
<?php if(osc_user_is_company()) { ?>




User::newInstance()->osc_user_is_company()
this would work only, if item owner is loaded to the view... if i'm right on item pages the current logged user is loaded to the view
« Last Edit: July 28, 2017, 03:03:24 am by Liath »

andrei2987

  • Newbie
  • *
  • Posts: 40
Re: ad posting - only for company
« Reply #13 on: August 01, 2017, 11:57:39 am »
hi,

i tested with

Code: [Select]
<?php
$seller 
User::newInstance()->findByPrimaryKey(osc_item_user_id());
if (
$seller['b_company'] == '1') {
    ...
}
?>

but in not working
no button is displayed at all

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Re: ad posting - only for company
« Reply #14 on: August 01, 2017, 12:59:21 pm »
Try with osc_logged_user_id() instead of osc_item_user_id()

hi,

i tested with

Code: [Select]
<?php
$seller 
User::newInstance()->findByPrimaryKey(osc_item_user_id());
if (
$seller['b_company'] == '1') {
    ...
}
?>

but in not working
no button is displayed at all
« Last Edit: August 01, 2017, 02:09:06 pm by marius-ciclistu »