move article to trash

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
itstante88
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Jan 30, 2013 3:33 pm

move article to trash

Post by itstante88 » Mon Feb 24, 2014 11:47 pm

I am using j2store on my website.. the problem I have is that all my products are unique and I need to implement that whenever someone buys an item, and with j2store item is a regular joomla article, the item/article is moved to trash. So what I need is a function that will receive article id and move that article to trash.

I am not familiar with joomla framework, and I know a little bit of php, but I think I could make this happen with some help.

jgress-
Joomla! Ace
Joomla! Ace
Posts: 1097
Joined: Thu Sep 24, 2009 5:40 pm
Location: Austin, TX, USA

Re: move article to trash

Post by jgress- » Tue Feb 25, 2014 4:09 am

i would think that you would want to unpublish the item and not trash it until the order is complete. have you asked j2store about how to accomplish this?
Co-author Using Joomla, Second Edition (migration/upgrade included) http://www.usingjoomlabook.com
Find a Joomla User Group (JUG) near you http://community.joomla.org/user-groups.html

itstante88
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Jan 30, 2013 3:33 pm

Re: move article to trash

Post by itstante88 » Tue Feb 25, 2014 7:50 am

I have asked j2store but this requires "customization" that you need to request and pay for. And I asked can day do it and for how much but didn't get an answer yet. I imagine that it would take time more time and money then I want to spend on a small issue like this.

You are right, it probably is better solution to unpublish the article.. I will look into that but if you have any ideas please share them.

Thank you for your answer.

jgress-
Joomla! Ace
Joomla! Ace
Posts: 1097
Joined: Thu Sep 24, 2009 5:40 pm
Location: Austin, TX, USA

Re: move article to trash

Post by jgress- » Tue Feb 25, 2014 5:23 pm

i understand small budgets.

probably if i were in your shoes i would just manually unpublish the sold item as it sells. i'm assuming that j2store sends you a notification when a product sells so that you can process the order. if you simply add the step to your order fulfillment process to unpublish the item once sold, it's done and cost you nothing but a moment to click "unpublish." if you find yourself selling so many products that you can't keep up with this, then hopefully you're also making a profit and can afford to have the customization work done.

there is a forum here on the joomla forum where you can ask for professional services http://forum.joomla.org/viewforum.php?f=177. you might want to post there and see if you can afford the customization.

perhaps if you post in j2store's forum in the feature request forum someone might be able to do the customization for you for pay ... http://j2store.org/forum/4-j2store-feat ... uests.html.

those are my ideas and certainly i wish you the best!! :)
Co-author Using Joomla, Second Edition (migration/upgrade included) http://www.usingjoomlabook.com
Find a Joomla User Group (JUG) near you http://community.joomla.org/user-groups.html

itstante88
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Wed Jan 30, 2013 3:33 pm

Re: move article to trash

Post by itstante88 » Sat Mar 01, 2014 1:03 am

No here is what I tried to do:

$app =JFactory::getApplication();
$order_id = (int) $app->getUserState( 'j2store.order_id' );

// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

// Select all records from the orderitems table where order_id.
// Order it by the ordering field.
$query->select($db->quoteName('product_id'));
$query->from($db->quoteName('y7o01_j2store_orderitems'));
$query->where($db->quoteName('order_id') . '=' . $order_id);

// Reset the query using our newly populated query object.
$db->setQuery($query);

if ($db->getErrorNum()) {
echo $db->getErrorMsg();
}

$product_id= $db->loadColumn();

/*--------------------------------------------------------------------------------*/
// Create a new query object.
$query = $db->getQuery(true);

// Fields to update.
$fields = $db->quoteName('state') . ' = ' . '0';

$article_id = join(',',$product_id);

// Conditions for which records should be updated.
$condition = $db->quoteName('y7o01_content') . '.' . $db->quoteName('id') . ' IN ' . '('.$article_id.')' . ';';

$query->update($db->quoteName('organi98_organicstyle') . '.' . $db->quoteName('y7o01_content'))->set($fields)->where($condition);

$db->setQuery($query);

if ($db->getErrorNum()) {
echo $db->getErrorMsg();
}

$result = $db->getQuery();

I echo the results and they match!
So from the first query I get the producti_id/article_id array with all products that have been ordered.
And then I echo the second query..

UPDATE `organi98_organicstyle`.`y7o01_content` SET `state` =0 WHERE `y7o01_content`.`id` IN ( 70 ) ;

now here is the thing, when I copy and paste the echoed query into mysql it works but i doesn't work when it is called from this file.
Also, this works well on localhost from the file and within mysql but when online for some reason it doesn't..
I actually set the value in mysql and just copied the same one it produced and rebuilt it in this file so I can't understand why it doesn't work.
Mysql shows this error "The column name 'fulltext' is a MySQL reserved keyword." when I run the query in it but it does the job. I tried searching for why this error appears but can't find nothing related because I don't use 'fulltext' anywhere.

Joomla 2.5.18

Please help


Locked

Return to “Joomla! 2.5 Coding”