Search the Community
Showing results for tags 'append'.
-
My vessel template has a price field (actually field group: with price_currency, price_amount). But when the price is lowered, the listing should qualify to appear on a "Price Cuts" page automatically... so here's what I'm doing (or skip to the bottom): So I was thinking I could add another couple of read-only fields, price_amount_was (since it's unlikely that the currency would change) and price_cut_date. price_amount_was would default to the set price once one is set on save (starts empty, stays empty until a price is set and the page saved). price_cut_date would be null by default. Then another hook after page save would check if the price_amount is lower than price_amount_was, and if so, change the price_cut_date to the current day. Then my Price Cuts page could just show "template=vessel, limit=10, price_cut_date!='', sort=-price_cut_date". But if I wanted to keep a history of price cuts for each listing, that wouldn't work. I could use a repeater field but I don't think that's all that necessary, since only the current and last price (or I guess that'd be second-to-last, last is current) need be queryable. I could add another read-only textarea field, price_history, and on every save that the price is changed, append the price and date (comma-separated, followed by a newline). So that's what I'm trying to do now, but I don't know how to append to price_history. In my module init I hook after page save, this function: protected function setPriceHistory($event) { $page = $event->arguments('page'); if($page->template != 'vessel') return; if($page->price_amount) { //$this->message("Price exists"); if(!$page->price_amount_hold) { $page->set("price_amount_hold", $page->price_amount)->save(); // append price_amount, date(), newline to price_history $this->message("Updated hold price to current price."); } if($page->price_amount < $page->price_amount_hold) { $page->set("price_amount_was", $page->price_amount_hold)->set("price_amount_hold", $page->price_amount)->set("price_cut_date", wireDate('Y-m-d'))->save(); $this->message("Price Cut set on {$page->price_cut_date}."); } } } So you see that commented out line in if(!$page->price_amount_was){}... I could set the value, but I don't want to reset it, just add to it. Thanks.