Beispiel #1
0
 /**
  * Gets the sources registered with the system
  * 
  * @return unknown
  */
 public static function sources()
 {
     $sources = (array) \Base::instance()->get('dsc.search.sources');
     $sources = \Dsc\ArrayHelper::sortArrays($sources, 'priority');
     // TODO Put the default up top
     return $sources;
 }
Beispiel #2
0
 public function notifications()
 {
     $this->settings_route = '/admin/shop/settings/notifications';
     switch ($this->app->get('VERB')) {
         case "POST":
         case "post":
             $data = $this->app->get('REQUEST');
             $__emails = explode(",", \Dsc\ArrayHelper::get($data, '__notifications_orders_emails'));
             $__emails = array_filter(array_unique($__emails));
             $emails = array();
             foreach ($__emails as $__email) {
                 if (\Mailer\Abstracts\Sender::isEmailAddress($__email)) {
                     $emails[] = $__email;
                 }
             }
             $this->app->set('REQUEST.notifications.orders.emails', $emails);
             // do the save and redirect to $this->settings_route
             return $this->save();
             break;
     }
     $flash = \Dsc\Flash::instance();
     $this->app->set('flash', $flash);
     $settings = \Shop\Models\Settings::fetch();
     $flash->store($settings->cast());
     $this->app->set('meta.title', 'Notifications | Shop');
     echo $this->theme->render('Shop/Admin/Views::settings/notifications.php');
 }
Beispiel #3
0
 public function __construct($source = array(), $options = array())
 {
     parent::__construct($source, $options);
     foreach ($this->attributes as $key => $attribute) {
         $this->attributes[$key] = (new \Shop\Models\Prefabs\Attribute($attribute))->cast();
         foreach ($this->attributes[$key]['options'] as $ao_key => $ao_value) {
             $this->attributes[$key]['options'][$ao_key] = (new \Shop\Models\Prefabs\AttributeOption($ao_value))->cast();
         }
     }
     foreach ($this->variants as $key => $variant) {
         if (empty($this->variants[$key]['id'])) {
             $this->variants[$key]['id'] = (string) new \MongoId();
         }
         foreach ($this->attributes as $a_key => $attribute) {
             foreach ($this->attributes[$a_key]['options'] as $ao_key => $ao_value) {
                 if ($this->attributes[$a_key]['options'][$ao_key]['value'] == $variant['price']) {
                     $this->variants[$key]['key'] = $this->attributes[$a_key]['options'][$ao_key]['id'];
                     break 2;
                 }
             }
         }
     }
     $this->set('shipping.enabled', false);
     $this->set('policies.track_inventory', false);
     $this->set('policies.variant_pricing.enabled', true);
     $this->variants = \Dsc\ArrayHelper::sortArrays(array_values($this->variants), 'ordering');
 }
Beispiel #4
0
 public static function refresh($force = false)
 {
     $settings = \Shop\Models\Settings::fetch();
     if (empty($settings->{'currency.openexchangerates_api_id'})) {
         static::log('Could not refresh list of valid currencies.  Please provide an open exchange rates API ID in the Shop Configuration page', 'ERROR');
         return false;
     }
     // once a day is enough
     if (!empty($settings->currencies_last_refreshed) && $settings->currencies_last_refreshed > time() - 24 * 60 && empty($force)) {
         return false;
     }
     $oer = new \Shop\Lib\OpenExchangeRates($settings->{'currency.openexchangerates_api_id'});
     if ($response = $oer->currencies()) {
         if ($currencies = \Dsc\ArrayHelper::fromObject($response)) {
             foreach ($currencies as $code => $title) {
                 $currency = (new static())->setParam('conditions', array('code' => $code))->getItem();
                 if (empty($currency->id)) {
                     $currency = new static();
                 }
                 $currency->code = $code;
                 $currency->title = $title;
                 $currency->store();
             }
             $settings->currencies_last_refreshed = time();
             $settings->save();
         }
     }
     return true;
 }
Beispiel #5
0
 /**
  * Get the value of a cookie.
  *
  * @param  string  $name
  * @param  mixed   $default
  * @return string
  */
 public static function get($name, $default = null)
 {
     if (isset(static::$jar[$name])) {
         return static::$jar[$name]['value'];
     }
     return \Dsc\ArrayHelper::get($_COOKIE, $name, $default);
 }
Beispiel #6
0
 public function options()
 {
     $data = \Base::instance()->get('REQUEST');
     // get the metadata.type
     if (!($type = \Dsc\ArrayHelper::get($data, 'type'))) {
         return;
     }
     $view = \Dsc\System::instance()->get('theme');
     $view->event = $view->trigger('onDisplayAdminModuleEdit', array('module' => $type, 'item' => $this->getItem(), 'tabs' => array(), 'content' => array()));
     $html = $view->renderLayout('Modules/Admin/Views::modules/options.php');
     $response = $this->getJsonResponse(array('message' => $html));
     return $this->outputJson($response);
 }
Beispiel #7
0
 /**
  * Get all the images associated with a product
  * incl.
  * featured image, related images, etc
  *
  * @param unknown $cast
  * @return array
  */
 public function images()
 {
     $featured_image = array();
     if (!empty($this->featured_image['slug'])) {
         $featured_image = array($this->featured_image['slug']);
     }
     $related_images = \Dsc\ArrayHelper::where($this->images, function ($key, $ri) {
         if (!empty($ri['image'])) {
             return $ri['image'];
         }
     });
     $images = array_unique(array_merge(array(), (array) $featured_image, (array) $related_images));
     return $images;
 }
Beispiel #8
0
 /**
  * Process a checkout and mark it as completed if successful.
  * Processing a checkout means creating an order object.  
  * 
  * @return \Shop\Models\Checkout
  */
 public function createOrder($refresh = false)
 {
     if (!empty($this->__order) && empty($refresh)) {
         return $this;
     }
     // Convert the cart to an Order object
     $this->__order = \Shop\Models\Orders::fromCart($this->cart());
     // Add payment details if applicable
     // Don't add the credit card number form the PaymentData to the cart, it shouldn't be stored in the order object in the DB
     $payment_data = (array) $this->paymentData();
     \Dsc\ArrayHelper::clear($payment_data, 'card');
     $this->__order->addPayment($payment_data);
     return $this;
 }
Beispiel #9
0
 /**
  * Target for POST to create new record
  */
 public function add()
 {
     $f3 = \Base::instance();
     $flash = \Dsc\Flash::instance();
     $data = \Base::instance()->get('REQUEST');
     //\Dsc\System::addMessage( \Dsc\Debug::dump($data) );
     if (!$this->canCreate($data)) {
         throw new \Exception('Not allowed to add record');
     }
     $__customers = explode(",", \Dsc\ArrayHelper::get($data, '__customers'));
     $__emails = explode(",", \Dsc\ArrayHelper::get($data, '__emails'));
     $emails = array_filter(array_unique(array_merge(array(), $__customers, $__emails)));
     if (!empty($emails)) {
         try {
             $this->getModel()->issueToEmails($data, $emails);
             switch ($data['submitType']) {
                 case "save_new":
                     $route = $this->create_item_route;
                     break;
                 case "save_close":
                 default:
                     $route = $this->list_route;
                     break;
             }
             $this->setRedirect($route);
         } catch (\Exception $e) {
             \Dsc\System::instance()->addMessage('Save failed with the following errors:', 'error');
             \Dsc\System::instance()->addMessage($e->getMessage(), 'error');
             if (\Base::instance()->get('DEBUG')) {
                 \Dsc\System::instance()->addMessage($e->getTraceAsString(), 'error');
             }
             // redirect back to the create form with the fields pre-populated
             \Dsc\System::instance()->setUserState('use_flash.' . $this->create_item_route, true);
             $flash->store($data);
             $this->setRedirect($this->create_item_route);
         }
     } else {
         // create just a single gift card
         $this->doAdd($data);
     }
     \Dsc\System::addMessage('Gift cards issued');
     if ($route = $this->getRedirect()) {
         \Base::instance()->reroute($route);
     }
     return;
 }
Beispiel #10
0
 /**
  * This method returns update clause which will be later on passed to collection
  * 
  * @param 	$data		Data from request
  * @param	$params		Arrays with possible additional params (for different modes of updater
  * 
  * @return	Based on mode of updater, either update clause or updated document
  */
 public function getUpdateClause($data, $params = array())
 {
     // check required parameters
     if (!$this->checkParams($params)) {
         return null;
     }
     $data = $this->inputFilter()->clean($data, "string");
     switch ($this->attribute->getUpdaterMode()) {
         case 0:
             throw new \Exception("Unsupported mode for this operation in Mass Update");
             break;
         case 1:
             $doc = $params['document'];
             $name_with_idx = $this->getNameWithIdx();
             $dataset = $params['dataset'];
             $attr_collection = $this->attribute->getAttributeCollection();
             $name_type = $name_with_idx . '_type';
             $name_op = $name_with_idx . '_operation';
             // cant find type => skip this
             if (empty($dataset[$name_type]) || empty($dataset[$name_op])) {
                 return null;
             }
             $act_data = \Dsc\ArrayHelper::get($doc, $attr_collection);
             $res = '';
             $type = $dataset[$name_type];
             $op = $dataset[$name_op];
             switch ($op) {
                 case '+':
                     $res = $this->handleAdding($type, $act_data, $data);
                     break;
                 case '-':
                     $res = $this->handleRemoving($type, $act_data, $data);
                     break;
                 default:
                     $res = $act_data;
                     break;
             }
             \Dsc\ObjectHelper::set($doc, $attr_collection, $res);
             return $doc;
         default:
             throw new \Exception("Unknown type of operation in Mass Update");
     }
 }
Beispiel #11
0
    echo $network;
    ?>
">
                        <i class="fa fa-times"></i>
                    </a>                                        
                </div>
                <div class="panel-body">
                    <p><img src="<?php 
    echo $profile_img;
    ?>
" alt="<?php 
    echo $name;
    ?>
" class="img-responsive" /></p>
                    <a href="<?php 
    echo \Dsc\ArrayHelper::get($profile, 'profile.profileURL');
    ?>
" target="_blank"><?php 
    echo $name;
    ?>
</a>
                </div>
            </div>
    
        </div>
                    
        <?php 
    $n++;
    if ($n % 4 == 0 || $n == $count) {
        ?>
</div><?php 
Beispiel #12
0
                                <p>
                                    <label>SKU:</label> <?php 
            echo $item->{'tracking.sku'};
            ?>
                                </p>
                                <?php 
        }
        ?>
                                
                                <?php 
        if ($item->{'categories'}) {
            ?>
                    			<p>			                        			
                    				<label>Categories:</label>
									<span class='label label-warning'><?php 
            echo implode("</span> <span class='label label-warning'>", \Dsc\ArrayHelper::getColumn((array) $item->{'categories'}, 'title'));
            ?>
</span>
                    			</p>                                
                                <?php 
        }
        ?>
                                
                                <?php 
        if ($item->{'tags'}) {
            ?>
                    			<p>
                    				<label>Tags:</label>
									<span class='label label-info'><?php 
            echo implode("</span> <span class='label label-info'>", (array) $item->tags);
            ?>
Beispiel #13
0
 /**
  * Load the product for the specified wishlist item
  * 
  * @param unknown $wishlistitem
  * @return \Shop\Models\Products
  */
 public static function product($wishlistitem)
 {
     $variant_id = \Dsc\ArrayHelper::get($wishlistitem, 'variant_id');
     try {
         $return = (new \Shop\Models\Variants())->getById($variant_id);
     } catch (\Exception $e) {
         $return = new \Shop\Models\Products();
     }
     return $return;
 }
Beispiel #14
0
 /**
  *	Delete field
  *	@return NULL
  *	@param $key string
  **/
 function clear($key)
 {
     \Dsc\ArrayHelper::clear($this->document, $key);
 }
Beispiel #15
0
		                        			</div>
		                        			<div>
		                        				<label>Author:</label> <a href="./admin/user/edit/<?php 
        echo $item->{'author.id'};
        ?>
" title="<?php 
        echo $item->{'author.name'};
        ?>
"><?php 
        echo $item->{'author.name'};
        ?>
</a>
		                        			</div>
		                        			<div>
			                        			<?php 
        $categories = \Dsc\ArrayHelper::getColumn((array) $item->categories, 'title');
        ?>
		                        				<label>Categories:</label>
												<span class='label label-warning'><?php 
        echo implode("</span> <span class='label label-warning'>", (array) $categories);
        ?>
</span>
		                        			</div>
		                        			<div>
		                        				<label>Tags:</label>
												<span class='label label-info'><?php 
        echo implode("</span> <span class='label label-info'>", (array) $item->tags);
        ?>
</span>
		                        			</div>
		                        		</div>
Beispiel #16
0
            <div class="list-group-item">
                
                <div class="row">
                    <div class="col-xs-2 col-md-1">
                        <input type="checkbox" class="icheck-input icheck-id" name="ids[]" value="<?php 
        echo $item->id;
        ?>
">
                    </div>
                    <div class="col-xs-10 col-md-3">
                        <?php 
        if ($item->groups) {
            ?>
                        <div class="pull-right">
                            <span class='label label-default'><?php 
            echo implode("</span> <span class='label label-default'>", \Dsc\ArrayHelper::getColumn((array) $item->groups, 'title'));
            ?>
</span>
                        </div>
                        <?php 
        }
        ?>
                        
                        
                        <h4>
                            <a href="./admin/shop/campaign/read/<?php 
        echo $item->id;
        ?>
">
                                <?php 
        echo $item->ancestorsIndentedTitle();
Beispiel #17
0
 public function cvnMatch($data = array())
 {
     if (is_object($data)) {
         $data = \Dsc\ArrayHelper::fromObject($data);
     }
     if (!is_array($data)) {
         return null;
     }
     // check CVN response
     /*
     D The transaction was considered to be suspicious by the issuing bank.
     I The CVN failed the processor's data validation.
     M The CVN matched.
     N The CVN did not match.
     P The CVN was not processed by the processor for an unspecified reason.
     S The CVN is on the card but was not included in the request.
     U Card verification is not supported by the issuing bank.
     X Card verification is not supported by the card association.
     1 Card verification is not supported for this processor or card type.
     2 An unrecognized result code was returned by the processor for the card
     verification response.
     3 No result code was returned by the processor.
     */
     $cv_result = isset($data['auth_cv_result']) ? $data['auth_cv_result'] : null;
     switch ($cv_result) {
         // No Match
         case "D":
         case "I":
         case "N":
         case "S":
             return false;
             break;
             // Match
         // Match
         case "M":
             return true;
             break;
             // Unavailable
         // Unavailable
         case "P":
         case "U":
         case "X":
         case "1":
         case "2":
         case "3":
         default:
             return null;
             break;
     }
 }
Beispiel #18
0
echo date('Y-m-d H:i:s', $item->{'metadata.created.time'});
?>
                                    </div>
                                    <div class="col-md-10">
                                        Created
                                    </div>
                                </div>
                            </li>                        
                            <?php 
foreach ($item->history as $history) {
    ?>
                                <li class="list-group-item">
                                    <div class="row">
                                        <div class="col-md-2">
                                            <?php 
    echo \Dsc\ArrayHelper::get($history, 'created.local');
    ?>
                                        </div>
                                        <div class="col-md-10">
                                            <?php 
    $dump = $history;
    unset($dump['created']);
    ?>
                                            <?php 
    echo \Dsc\Debug::dump($dump);
    ?>
                                        </div>
                                    </div>
                                </li>
                            <?php 
}
Beispiel #19
0
	<?php 
    }
} else {
    ?>
    <div class="shipping-methods">
    <?php 
    foreach ($cart->shippingMethods() as $method_array) {
        $method = new \Shop\Models\ShippingMethods($method_array);
        ?>
		<div class="form-field radio">
			<label class="control-label">
				<input data-required="true" type="radio" name="checkout[shipping_method]" value="<?php 
        echo $method->{'id'};
        ?>
" <?php 
        if (\Dsc\ArrayHelper::get($cart, 'checkout.shipping_method') == $method->{'id'}) {
            echo 'checked';
        }
        ?>
 />
				<?php 
        echo $method->{'name'};
        ?>
 &mdash; <?php 
        if (empty($method->total())) {
            echo "FREE";
        } else {
            echo \Shop\Models\Currency::format($method->total());
        }
        ?>
			</label>
Beispiel #20
0
 /**
  * Move this model one position to the right in the same level of the tree
  * 
  * @return \Dsc\Mongo\Collections\Nested
  */
 public function moveDown()
 {
     $this->rebuildTree($this->tree);
     // Get the sibling immediately to the left of this node
     $sibling = (new static())->load(array('tree' => $this->tree, 'lft' => $this->rgt + 1));
     // fail of no sibling found
     if (empty($sibling->id)) {
         return $this;
     }
     $ids = array();
     // Get the primary keys of descendant nodes, including this node's
     if ($descendants = $this->getDescendants()) {
         $ids = \Dsc\ArrayHelper::getColumn($descendants, '_id');
     }
     $width = (int) ($this->rgt - $this->lft + 1);
     $sibling_width = (int) ($sibling->rgt - $sibling->lft + 1);
     // Shift left and right values for the node and its children.
     $result = $this->collection()->update(array('lft' => array('$gte' => $this->lft, '$lte' => $this->rgt), 'tree' => $this->tree), array('$inc' => array('lft' => $sibling_width, 'rgt' => $sibling_width)), array('multiple' => true));
     // Shift left and right values for the sibling and its children
     // explicitly excluding the node's descendants
     $result = $this->collection()->update(array('_id' => array('$nin' => $ids), 'lft' => array('$gte' => $sibling->lft, '$lte' => $sibling->rgt), 'tree' => $this->tree), array('$inc' => array('lft' => -$width, 'rgt' => -$width)), array('multiple' => true));
     return $this;
 }
Beispiel #21
0
 /**
  * Determines if any variants exist for the provided view file
  *
  * @param unknown $view            
  * @param string $site            
  * @return multitype:
  */
 public function variants($view, $site = 'site')
 {
     $return = array();
     $view = str_replace(".php", "", $view);
     $view = str_replace("::", "/", $view);
     $view = str_replace("\\", "/", $view);
     $pieces = explode('/', $view);
     $themes = (array) \Base::instance()->get('dsc.themes.' . $site);
     foreach ($themes as $theme => $theme_path) {
         // an overrides folder exists in this theme, let's check for the presence of an override for the requested view file
         $dir = \Dsc\Filesystem\Path::clean($theme_path . "Overrides/");
         if ($dir = \Dsc\Filesystem\Path::real($dir)) {
             $path = \Dsc\Filesystem\Path::clean($dir . "/" . $view);
             if ($path = \Dsc\Filesystem\Path::real($path)) {
                 $files = \Dsc\Filesystem\Folder::files($path);
                 if ($files) {
                     $return = \Dsc\ArrayHelper::set($return, $theme, $files);
                 }
             }
         }
     }
     // now find the requested file's original app, and its corresponding view files
     $app = $pieces[0];
     $apps = (array) \Base::instance()->get('dsc.apps');
     if (array_key_exists($app, $apps)) {
         $dir = $apps[$app];
         unset($pieces[0]);
         $view = implode('/', $pieces);
         if ($dir = \Dsc\Filesystem\Path::real($dir)) {
             $path = \Dsc\Filesystem\Path::clean($dir . "/" . $view);
             if ($path = \Dsc\Filesystem\Path::real($path)) {
                 $files = \Dsc\Filesystem\Folder::files($path);
                 if ($files) {
                     $return = \Dsc\ArrayHelper::set($return, $app, $files);
                 }
             }
         }
     }
     return $return;
 }
Beispiel #22
0
        <?php 
$pieces = explode('?', \Dsc\Pagination::checkRoute(str_replace($BASE, '', $URI)));
$current = $pieces[0];
$list = (new \Admin\Models\Nav\Primary())->setState('filter.root', false)->setState('filter.tree', \Admin\Models\Settings::fetch()->get('admin_menu_id'))->setState('order_clause', array('tree' => 1, 'lft' => 1))->getItems();
// push the default to the beginning of the list
array_unshift($list, new \Admin\Models\Nav\Primary(array('route' => './admin', 'title' => 'Dashboard', 'icon' => 'fa-home', 'depth' => 2)));
?>
        
        <ul>
        <?php 
foreach ($list as $key => $item) {
    if (!($hasAccess = \Dsc\System::instance()->get('acl')->isAllowed($identity->role, $item->route, '*'))) {
        continue;
    }
    $class = !empty($item->class) ? $item->class : 'menu-item';
    $selected = $current == $item->route || !empty($item->base) && strpos($current, $item->base . '/') !== false || \Dsc\String::inStrings(\Dsc\ArrayHelper::getColumn($item->getDescendants(), 'route'), $current);
    if ($selected || $current == str_replace('./', '/', $item->route)) {
        $class .= " active open";
    }
    if ($item->hasDescendants()) {
        $class .= " dropdown";
    }
    if (empty($item->route)) {
        $item->route = 'javascript:void(0);';
    } elseif ($item->route[0] == '/') {
        $item->route = '.' . $item->route;
    }
    echo '<li data-depth="' . $item->getDepth() . '" class="' . $class . '">';
    // is this a module?
    // or just a regular link?
    echo '<a href="' . $item->route . '" style="">';
Beispiel #23
0
        echo \Dsc\ArrayHelper::get($item, 'attribute_title');
        ?>
</small>
                </div>
                <?php 
    }
    ?>
                <div>
                    <small>
                    <span class="quantity"><?php 
    echo $quantity = \Dsc\ArrayHelper::get($item, 'quantity');
    ?>
</span>
                    x
                    <span class="price"><?php 
    echo \Shop\Models\Currency::format($price = \Dsc\ArrayHelper::get($item, 'price'));
    ?>
</span>
                    </small> 
                </div>
            </h4>
        </td>
        <td style="vertical-align: top; text-align: right;">
            <h4>
                <?php 
    echo \Shop\Models\Currency::format($quantity * $price);
    ?>
            </h4>
        </td>
    </tr>        
    <?php 
Beispiel #24
0
 /**
  * \T (tab) delimited feed of products
  * 
  * http://www.pepperjamnetwork.com/doc/product_feed_advanced.html
  * 
  */
 public function productsTxt()
 {
     $settings = \Shop\Models\Settings::fetch();
     if (!$settings->{'feeds.pepperjam_products.enabled'}) {
         return;
     }
     $this->app->set('CACHE', true);
     $cache = \Cache::instance();
     $cache_period = 3600 * 24;
     if ($cache->exists('pepperjam.products_text', $string)) {
         header('Content-Type: text/plain; charset=utf-8');
         echo $string;
         exit;
     }
     $base = \Dsc\Url::base();
     $model = (new \Shop\Models\Products())->setState('filter.published_today', true)->setState('filter.inventory_status', 'in_stock')->setState('filter.publication_status', 'published');
     $conditions = $model->conditions();
     $conditions['product_type'] = array('$nin' => array('giftcard', 'giftcards'));
     $cursor = \Shop\Models\Products::collection()->find($conditions)->sort(array('title' => 1));
     //->limit(10);
     /**
      * name	sku	buy_url	image_url	description_short	description_long	price	manufacturer
      */
     $column_headers = array('name', 'sku', 'buy_url', 'image_url', 'description_short', 'description_long', 'price', 'manufacturer');
     $string = implode("\t", $column_headers) . "\r\n";
     foreach ($cursor as $product_doc) {
         $product = new \Shop\Models\Products($product_doc);
         foreach ($product->variantsInStock() as $variant) {
             $valid = true;
             $price = $product->price($variant['id']);
             // Skip products where price == 0.00
             if (empty($price)) {
                 continue;
             }
             $pieces = array('name' => null, 'sku' => null, 'buy_url' => null, 'image_url' => null, 'description_short' => null, 'description_long' => null, 'price' => null, 'manufacturer' => null);
             $pieces['name'] = $product->title;
             $sku = $variant['sku'] ? $variant['sku'] : $product->{'tracking.sku'};
             if (!$sku) {
                 $sku = $variant['id'];
             }
             $pieces['sku'] = $sku;
             $pieces['buy_url'] = $base . 'shop/product/' . $product->slug . '?variant_id=' . $variant['id'];
             // image_link
             if ($image = $variant['image'] ? $variant['image'] : $product->{'featured_image.slug'}) {
                 $pieces['image_url'] = $base . 'asset/' . $image;
             }
             $pieces['description_short'] = $product->title . ' ';
             if ($attribute_title = \Dsc\ArrayHelper::get($variant, 'attribute_title')) {
                 $pieces['description_short'] .= $attribute_title;
             }
             $pieces['description_short'] = trim($pieces['description_short']);
             $pieces['description_long'] = strip_tags($product->getAbstract());
             $pieces['price'] = $price;
             if ($brand = $settings->{'feeds.pepperjam_products.brand'}) {
                 $pieces['manufacturer'] = $brand;
             }
             global $product;
             //walk peices logging empty values and omiting them
             array_walk($pieces, function (&$value, $key) {
                 global $product;
                 if (empty($value)) {
                     \Dsc\Mongo\Collections\Logs::add($product->title . ' | ID: ' . $product->id . ' is missing ' . $key, 'WARNING', 'PepperJam');
                     $valid = false;
                 }
             });
             if ($valid) {
                 $string .= implode("\t", $pieces) . "\r\n";
             }
         }
     }
     $cache->set('pepperjam.products_text', $string, $cache_period);
     header('Content-Type: text/plain; charset=utf-8');
     echo $string;
     exit;
 }
Beispiel #25
0
            dataType: 'json',
            data: function (term, page) {
                return {
                    q: term
                };
            },
            results: function (data, page) {
                return {results: data.results};
            }
        }
        <?php 
if ($flash->old('groups')) {
    ?>
        , initSelection : function (element, callback) {
            var data = <?php 
    echo json_encode(\Users\Models\Groups::forSelection(array('_id' => array('$in' => array_map(function ($input) {
        return new \MongoId($input);
    }, \Dsc\ArrayHelper::getColumn((array) $flash->old('groups'), 'id'))))));
    ?>
;
            callback(data);            
        }
        <?php 
}
?>
    });

});
</script>

<hr/>
Beispiel #26
0
 protected function doUpdate(array $data, $key = null)
 {
     if (empty($this->list_route)) {
         throw new \Exception('Must define a route for listing the items');
     }
     if (empty($this->create_item_route)) {
         throw new \Exception('Must define a route for creating the item');
     }
     if (empty($this->edit_item_route)) {
         throw new \Exception('Must define a route for editing the item');
     }
     if (!isset($data['submitType'])) {
         $data['submitType'] = "save_edit";
     }
     $f3 = \Base::instance();
     $flash = \Dsc\Flash::instance();
     $model = $this->getModel();
     $this->item = $this->getItem();
     // save
     $save_as = false;
     try {
         $values = $data;
         unset($values['submitType']);
         //\Dsc\System::instance()->addMessage(\Dsc\Debug::dump($values), 'warning');
         if ($data['submitType'] == 'save_as') {
             $this->item = $model->saveAs($this->item, $values);
             \Dsc\System::instance()->addMessage('Item cloned. You are now editing the new item.', 'success');
         } else {
             $this->item = $model->update($this->item, $values);
             \Dsc\System::instance()->addMessage('Item updated', 'success');
         }
     } catch (\Exception $e) {
         \Dsc\System::instance()->addMessage('Save failed with the following errors:', 'error');
         \Dsc\System::instance()->addMessage($e->getMessage(), 'error');
         foreach ($model->getErrors() as $error) {
             \Dsc\System::instance()->addMessage($error, 'error');
         }
         if ($f3->get('AJAX')) {
             // output system messages in response object
             return $this->outputJson($this->getJsonResponse(array('error' => true, 'message' => \Dsc\System::instance()->renderMessages())));
         }
         // redirect back to the edit form with the fields pre-populated
         \Dsc\System::instance()->setUserState('use_flash.' . $this->edit_item_route, true);
         $flash->store($data);
         $id = $this->item->get($this->getItemKey());
         $route = str_replace('{id}', $id, $this->edit_item_route);
         $this->setRedirect($route);
         return false;
     }
     // redirect to the editing form for the new item
     if (method_exists($this->item, 'cast')) {
         $this->item_data = $this->item->cast();
     } else {
         $this->item_data = \Dsc\ArrayHelper::fromObject($this->item);
     }
     if ($f3->get('AJAX')) {
         return $this->outputJson($this->getJsonResponse(array('message' => \Dsc\System::instance()->renderMessages(), 'result' => $this->item_data)));
     }
     switch ($data['submitType']) {
         case "save_new":
             $route = $this->create_item_route;
             break;
         case "save_close":
             $route = $this->list_route;
             break;
         case "save_as":
         default:
             $flash->store($this->item_data);
             $id = $this->item->get($this->getItemKey());
             $route = str_replace('{id}', $id, $this->edit_item_route);
             break;
     }
     $this->setRedirect($route);
     return $this;
 }
Beispiel #27
0
<?php

if ($categories = \Shop\Models\Categories::find()) {
    ?>
<div>

<select name="category_ids[]" class="select2" >

    <?php 
    $current = \Dsc\ArrayHelper::getColumn((array) $flash->old('categories'), 'id');
    ?>
    <?php 
    foreach ($categories as $one) {
        ?>
    <option value="<?php 
        echo $one->_id;
        ?>
" <?php 
        if (in_array($one->_id, $current)) {
            echo "selected='selected'";
        }
        ?>
>
        <?php 
        echo @str_repeat("&ndash;", substr_count(@$one->path, "/") - 1) . " " . $one->title;
        ?>
    </option>
    <?php 
    }
    ?>
 
Beispiel #28
0
    {
        <?php 
    $title = \Dsc\ArrayHelper::get($item, 'product.title');
    if (\Dsc\ArrayHelper::get($item, 'attribute_title')) {
        $title .= ' - ' . \Dsc\ArrayHelper::get($item, 'attribute_title');
    }
    ?>
        
        'sku': '<?php 
    echo \Dsc\ArrayHelper::get($item, 'sku');
    ?>
',
        'name': '<?php 
    echo $title;
    ?>
',
        'price': <?php 
    echo (double) \Dsc\ArrayHelper::get($item, 'price');
    ?>
,
        'quantity': <?php 
    echo (int) \Dsc\ArrayHelper::get($item, 'quantity');
    ?>
    }
    <?php 
    $n++;
}
?>
    ]
});
</script>
Beispiel #29
0
 /**
  * Get an item from an object using dot notation
  *
  * @param  array   $array
  * @param  string  $key
  * @param  mixed   $default
  * @return mixed
  */
 public static function get($object, $key, $default = null)
 {
     $array = \Dsc\ArrayHelper::fromObject($object);
     return \Dsc\ArrayHelper::get($array, $key, $default);
 }
Beispiel #30
0
 /**
  * This method encrypts fields in provided array
  *
  * @param $arr Array
  *            field to be encrypted
  *            
  * @return Array with encrypted fields
  */
 private function encryptFieldsModel($arr)
 {
     if (!empty($this->__config['encrypted_fields'])) {
         $encrypted_fields = $this->__config['encrypted_fields'];
         if (is_array($encrypted_fields) === false) {
             $encrypted_fields = array($encrypted_fields);
         }
         foreach ($encrypted_fields as $field) {
             $field_text = \Dsc\ArrayHelper::get($arr, $field);
             if (!is_null($field_text)) {
                 \Dsc\ArrayHelper::set($arr, $field, $this->encryptTextBase64($field_text));
             }
         }
     }
     return $arr;
 }