public function forSelection() { $term = $this->input->get('q', null, 'default'); $key = new \MongoRegex('/' . $term . '/i'); $results = \Shop\Models\Collections::forSelection(array('title' => $key)); $response = new \stdClass(); $response->more = false; $response->term = $term; $response->results = $results; return $this->outputJson($response); }
public function products() { $model = (new \Shop\Models\Products())->populateState(); $id = $this->inputfilter->clean($this->app->get('PARAMS.id'), 'alnum'); try { $collection = (new \Shop\Models\Collections())->setState('filter.id', $id)->getItem(); if (empty($collection->id)) { throw new \Exception('Invalid Collection'); } $conditions = \Shop\Models\Collections::getProductQueryConditions($collection->id); if (!$model->getState('list.limit')) { $model->setState('list.limit', '100'); } $paginated = $model->setParam('conditions', $conditions)->setState('list.sort', array(array('collections.' . $id . '.ordering' => 1)))->paginate(); $this->app->set('paginated', $paginated); $this->app->set('collection', $collection); $this->app->set('state', $model->getState()); } catch (\Exception $e) { \Dsc\System::addMessage((string) $e, 'error'); $this->app->reroute('/admin/shop/collections'); } $this->app->set('meta.title', 'Manually Sort Products in Collection | Shop'); echo $this->theme->renderTheme('Shop/Admin/Views::collections/products.php'); }
minimumInputLength: 3, ajax: { url: "./admin/shop/collections/forSelection", dataType: 'json', data: function (term, page) { return { q: term }; }, results: function (data, page) { return {results: data.results}; } } <?php if ($flash->old('discount_target_collections')) { ?> , initSelection : function (element, callback) { var data = <?php echo json_encode(\Shop\Models\Collections::forSelection(array('_id' => array('$in' => array_map(function ($input) { return new \MongoId($input); }, (array) $flash->old('discount_target_collections')))))); ?> ; callback(data); } <?php } ?> }); }); </script>
protected function afterSave() { parent::afterSave(); if (!empty($this->__update_products_ordering)) { // $to_update = find all products in this collection that dont have an ordering value for this collection // if there are some, // get a count of all products in this collection, set $start = count to push them to the end // loop though $to_update and set their ordering value = $start + $key $conditions = \Shop\Models\Collections::getProductQueryConditions($this->id); $conditions['collections.' . $this->id . '.ordering'] = null; $to_update = \Shop\Models\Products::collection()->distinct('_id', $conditions); if (!empty($to_update)) { $collection_id = (string) $this->id; unset($conditions['collections.' . $this->id . '.ordering']); $count = \Shop\Models\Products::collection()->count($conditions); foreach ($to_update as $key => $product_id) { $ordering = $count + $key; $product = (new \Shop\Models\Products())->setState('filter.id', (string) $product_id)->getItem(); if (!empty($product->id)) { $product->update(array('collections.' . $collection_id . '.ordering' => (int) $ordering), array('overwrite' => false)); } } } } }
<form class="form-horizontal" action="./admin/menu/create" method="post"> <div class="form-group"> <label for="link-url" class="col-sm-4 control-label">Collection</label> <div class="col-sm-8"> <?php if ($__items = \Shop\Models\Collections::find()) { ?> <select name="details[url]" class="form-control"> <?php foreach ($__items as $__item) { ?> <option value="./shop/collection/<?php echo $__item->slug; ?> "> <?php echo $__item->title; ?> </option> <?php } ?> </select> <?php } ?> </div> </div> <div class="form-group">
public function viewAllPaginate() { $slug = $this->inputfilter->clean($this->app->get('PARAMS.slug'), 'cmd'); $model = $this->getModel()->populateState(); try { $collection = (new \Shop\Models\Collections())->setState('filter.slug', $slug)->getItem(); if (empty($collection->id)) { throw new \Exception('Invalid Collection'); } $model->setState('filter.collection', $collection->id); $conditions = \Shop\Models\Collections::getProductQueryConditions($collection->id); if ($filter_tags = (array) $model->getState('filter.tags')) { if ($tags = array_filter(array_values($filter_tags))) { if (!empty($conditions['tags'])) { // Add this to an $and clause if (empty($conditions['$and'])) { $conditions['$and'] = array(); } $conditions['$and'][] = array('tags' => array('$in' => $tags)); } else { $conditions['tags'] = array('$in' => $tags); } } } switch ($model->getState('sort_by')) { // only use the collection's $collection->sort_by if the user hasn't set their own state, // which is populated in the model by populateState() case "collection-default": case "": switch ($collection->sort_by) { case "ordering-asc": $model->setState('list.sort', array(array('collections.' . $collection->id . '.ordering' => 1))); break; default: $model->handleSortBy($collection->sort_by); break; } break; } $model->setState('list.limit', 300); $paginated = $model->setParam('conditions', $conditions)->paginate(); } catch (\Exception $e) { return; } $this->app->set('paginated', $paginated); $view = \Dsc\System::instance()->get('theme'); $response = new \stdClass(); $response->more = 0; if (!empty($paginated->total_items)) { if ($paginated->total_items > $paginated->items_per_page * $paginated->current_page) { $response->next_page = $paginated->next_page; } $view_file = 'all_grid.php'; if ($collection->{'display.view'} && $view->findViewFile('Shop/Site/Views::collection/all_grid/' . $collection->{'display.view'})) { $view_file = 'all_grid/' . $collection->{'display.view'}; } $response->result = $view->renderView('Shop/Site/Views::collection/' . $view_file); //$response->result = $view->renderView('Shop/Site/Views::collection/all_grid.php'); } $this->outputJson($response); }
</td> <td class=""> <a href="./admin/shop/collection/edit/<?php echo $item->_id; ?> "> <?php echo $item->slug; ?> </a> </td> <td class=""> <?php echo \Shop\Models\Collections::productCount($item->_id); ?> </td> <td> <a href="./shop/collection/<?php echo $item->get('slug'); ?> " target="_blank">Preview</a> </td> <td class="text-center col-lg-2 col-md-3"> <?php if ($allow_preview) { ?> <a class="btn btn-xs btn-warning" target="_blank" href="./shop/collection/<?php
/** * Get all products targeted for this discount * * @return unknown */ public function targetProducts() { $discount_target_products = (array) $this->discount_target_products; foreach ((array) $this->discount_target_collections as $collection_id) { $collection_product_ids = \Shop\Models\Collections::productIds($collection_id); $discount_target_products = array_merge($discount_target_products, $collection_product_ids); } $discount_target_products = array_unique($discount_target_products); return $discount_target_products; }