Пример #1
0
 public function action_create()
 {
     try {
         if (!Valid::email(core::request('email'))) {
             $this->_error(__('Invalid email'), 501);
         } elseif (!is_numeric(core::request('id_product'))) {
             $this->_error(__('Invalid product'), 501);
         } else {
             $product = new Model_Product(core::request('id_product'));
             if ($product->loaded()) {
                 $user = Model_User::create_email(core::request('email'), core::request('name'));
                 $order = Model_Order::new_order($user, $product);
                 $order->confirm_payment(core::request('paymethod', 'API'), core::request('txn_id'), core::request('pay_date'), core::request('amount'), core::request('currency'), core::request('fee'));
                 //adding the notes
                 $order->notes = core::request('notes');
                 $order->save();
                 $this->rest_output(array('order' => self::get_order_array($order)));
             } else {
                 $this->_error(__('Something went wrong'), 501);
             }
         }
     } catch (Kohana_HTTP_Exception $khe) {
         $this->_error($khe);
     }
 }
Пример #2
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     $products = new Model_Product();
     $products->where('status', '=', Model_Product::STATUS_ACTIVE);
     $products->where('rate', 'IS NOT', NULL)->order_by('rate', 'desc')->order_by('created', 'asc');
     $products = $products->limit($this->products_limit)->cached()->find_all();
     $this->products = $products;
 }
Пример #3
0
 public function testattachOrderConfig()
 {
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel->config = '["hello", "world"]';
     $data = array('testing' => 'phase');
     $expected = array_merge(json_decode($productModel->config, 1), $data);
     $result = $this->service->attachOrderConfig($productModel, $data);
     $this->assertInternalType('array', $result);
     $this->assertEquals($expected, $result);
 }
Пример #4
0
 public function action_index()
 {
     $view = View::factory('home/main');
     $products = new Model_Product();
     $clients = new Model_Client();
     $user_session = Session::instance()->get('email');
     $view->valute = $clients->get_user_valute($user_session);
     $view->last_products = $products->get_newest_products();
     $view->discounts = $products->get_products_with_discounts();
     $this->template->content = $view->render();
 }
Пример #5
0
 /**
  * Deletes a product.
  *
  * @param Model_Product $product The product to delete.
  *
  * @return bool
  */
 public static function delete(Model_Product $product)
 {
     $product->status = 'deleted';
     try {
         $product->save();
     } catch (FuelException $e) {
         Log::error($e);
         return false;
     }
     Service_Event::trigger('product.delete', $product->seller, $product->to_array());
     return true;
 }
Пример #6
0
 public function action_item()
 {
     $product_id = $this->request->param('id');
     if (empty($product_id)) {
         throw new Exception("ID must not be empty!");
     }
     $view = View::factory('products/info');
     $products = new Model_Product();
     $clients = new Model_Client();
     $view->products = $products->get_product_by_id($product_id);
     $user_email = Session::instance()->get('email');
     $view->valute = $clients->get_user_valute($user_email);
     $this->template->content = $view->render();
 }
Пример #7
0
 public function before()
 {
     parent::before();
     $config = Kohana::$config->load('common');
     $this->template->name = $config->name;
     $this->template->stylesheets = $config->stylesheets;
     $categories = new Model_Category();
     $client = new Model_Client();
     $product = new Model_Product();
     $this->template->products = $product->get_random_product_with_discount();
     $this->template->valute = $client->get_user_valute(Session::instance()->get('email'));
     $this->template->categories = $categories->get_list_of_categories();
     $this->template->users = $client->get_user_data(Session::instance()->get('email'));
     $this->template->scripts = $config->scripts;
 }
Пример #8
0
 public function action_order()
 {
     define("SECONDS_PER_DAY", 3600 * 24);
     $now = time();
     $cart = Session::get('cart');
     $user = Model_User::find($this->sessUser->id);
     $cart_info = [];
     $order = Model_Order::forge();
     $order->user_id = $user->id;
     $order->created_at = $now;
     $order->save();
     if (!is_null($cart)) {
         foreach ($cart as $product_id => $quantity) {
             $product = Model_Product::find($product_id);
             $order_product = Model_OrderProduct::forge();
             $order_product->order_id = $order->id;
             $order_product->product_id = $product->id;
             $order_product->quantity = $quantity;
             $order_product->price = $product->price;
             $order_product->save();
         }
     }
     Session::delete('cart');
     return Response::redirect('/cart');
 }
Пример #9
0
 public function testFindByIdAutomaticallyLoadsRelationsForInstanceTranslation()
 {
     $name = 'New York';
     $description = 'En dansk beskrivelse';
     try {
         $item = new Model_Product();
         $item->name = $name;
         $item->Translation['DK']->description = $description;
         $item->Translation['EN']->description = 'Some english description';
         $item->save();
         $reopened = Doctrine_Core::getTable('Model_Product')->findOneById($item->id);
         $this->assertEqual($name, $reopened->name);
         $this->assertEqual($description, $reopened->Translation['DK']->description);
         $this->pass();
     } catch (Exception $e) {
         $this->fail($e->getMessage());
     }
 }
Пример #10
0
 /**
  * Index page
  * 
  * @access  public
  * @param   $slug
  */
 public function action_index($slug = false, $my_products = null)
 {
     if ($my_products == 1) {
         Model_Product::$filter_by_pricing_group = 'assigned';
     } else {
         Model_Product::$filter_by_pricing_group = 'not_assigned';
     }
     $this->show($slug);
 }
Пример #11
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get related products
                 $item->get_products = static::lazy_load(function () use($item) {
                     $products = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('group_id', $item->id);
                     }, 'product_id');
                     if (!empty($products)) {
                         $products = '(' . implode(',', array_keys($products)) . ')';
                         return Model_Product::find(function ($query) use($products, $item) {
                             $query->where('id', 'IN', \DB::expr($products));
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'products');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Group::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get group images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Group_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get group discount options
                 // Use one more item property (user_group_id)
                 // It can be set using methods (set_user_group_id and get_user_group_id)
                 $item->get_discount_options = static::lazy_load(function () use($item) {
                     $options = Model_Group_Options::find(array('where' => array('user_group_id' => $item->get_user_group_id(), 'product_group_id' => $item->id)));
                     return isset($options[0]) ? $options[0] : array();
                 }, $item->id, 'discount_options', 'object');
                 // Get group discount options
                 // Use one more item property (user_group_id)
                 // It can be set using methods (set_user_group_id and get_user_group_id)
                 $item->get_discounts = static::lazy_load(function () use($item) {
                     return Model_Group_Discounts::find(array('where' => array('user_group_id' => $item->get_user_group_id(), 'product_group_id' => $item->id), 'order_by' => array('qty' => 'asc')), 'qty');
                 }, $item->id, 'discounts');
                 // DO NOT CHANGE THIS TWO FUNCTIONS AS THEY ARE NEEDED
                 $item->set_user_group_id = function ($user_group_id = NULL) {
                     \Product\Model_Group::$user_group_id = $user_group_id;
                 };
                 $item->get_user_group_id = function () {
                     return \Product\Model_Group::$user_group_id;
                 };
             }
         }
     }
     // return the result
     return $result;
 }
 public function action_delete($id = null)
 {
     if ($product = Model_Product::find($id)) {
         $product->delete();
         Session::set_flash('success', e('Deleted product #' . $id));
     } else {
         Session::set_flash('error', e('Could not delete product #' . $id));
     }
     Response::redirect('admin/products');
 }
Пример #13
0
 public function deleteAction()
 {
     $id = $this->_getParam('id');
     $p = Model_Product::findbyId($id);
     if (!$p) {
         throw new Exception("Product id '" . $id . "' not found.");
     }
     $p->delete();
     echo json_encode(array('success' => true));
 }
Пример #14
0
 /**
  * [new_order description]
  * @param  Model_User    $user    [description]
  * @param  Model_Product $product [description]
  * @param  boolean       check_match_product, if set to false will update the order with the product if different
  * @return [type]                 [description]
  */
 public static function new_order(Model_User $user, Model_Product $product, $match_product = TRUE)
 {
     $order = new Model_Order();
     if ($user->loaded() and $product->loaded()) {
         //get if theres an unpaid order for this user we wwill use it..
         $order->where('id_user', '=', $user->id_user)->where('status', '=', Model_Order::STATUS_CREATED);
         //also check that matches the product for the order
         if ($match_product === TRUE) {
             $order->where('id_product', '=', $product->id_product)->where('amount', '=', $product->final_price())->where('currency', '=', $product->currency);
         }
         $order->limit(1)->find();
         //order didnt exist so lets create it.
         if ($order->loaded() === FALSE) {
             //create order
             $order = new Model_Order();
             $order->id_user = $user->id_user;
         }
         // no matter what happens if product is different save! this will also save the order if its new ;)
         if ($order->id_product != $product->id_product) {
             $order->ip_address = ip2long(Request::$client_ip);
             $order->id_product = $product->id_product;
             $order->currency = $product->currency;
             //add coupon ID and discount
             if (Model_Coupon::current()->loaded()) {
                 $order->id_coupon = Model_Coupon::current()->id_coupon;
             }
             $order->amount = $product->final_price();
             $order->VAT = euvat::vat_percentage();
             $order->VAT_number = $user->VAT_number;
             $order->country = $user->country;
             $order->city = $user->city;
             $order->postal_code = $user->postal_code;
             $order->address = $user->address;
             try {
                 $order->save();
             } catch (Exception $e) {
                 throw HTTP_Exception::factory(500, $e->getMessage());
             }
         }
     }
     return $order;
 }
Пример #15
0
 public function toApiArray(\Model_Product $model, $deep = true, $identity = null)
 {
     $repo = $model->getTable();
     $addons = $this->getAddonsApiArray($model);
     $config = $this->di['tools']->decodeJ($model->config, 1);
     $pricing = $repo->getPricingArray($model);
     $starting_from = $this->getStartingFromPrice($model);
     $result = array('id' => $model->id, 'product_category_id' => $model->product_category_id, 'type' => $model->type, 'title' => $model->title, 'form_id' => $model->form_id, 'slug' => $model->slug, 'description' => $model->description, 'unit' => $model->unit, 'priority' => $model->priority, 'created_at' => $model->created_at, 'updated_at' => $model->updated_at, 'pricing' => $pricing, 'config' => $config, 'addons' => $addons, 'price_starting_from' => $starting_from, 'icon_url' => $model->icon_url, 'allow_quantity_select' => $model->allow_quantity_select, 'quantity_in_stock' => $model->quantity_in_stock, 'stock_control' => $model->stock_control);
     if ($identity instanceof \Model_Admin) {
         $result['upgrades'] = $this->getUpgradablePairs($model);
         $result['status'] = $model->status;
         $result['hidden'] = $model->hidden;
         $result['setup'] = $model->setup;
         if ($model->product_category_id) {
             $productCategory = $this->di['db']->load('ProductCategory', $model->product_category_id);
             $result['category'] = array('id' => $productCategory->id, 'title' => $productCategory->title);
         }
     }
     return $result;
 }
Пример #16
0
 public function infoAction()
 {
     $args = $this->_getArguments();
     $productId = $args['id'];
     try {
         $modelProduct = Model_Product::getById($productId);
         $this->view->setParam('product', $modelProduct);
     } catch (Exception $e) {
         $this->view->setParam('error', $e->getMessage());
     }
 }
Пример #17
0
 public function action_orderDetails($order_id)
 {
     $order_info = [];
     $order_details = Model_OrderProduct::find('all', array('where' => array(['order_id', $order_id])));
     foreach ($order_details as $order_detail) {
         $product = Model_Product::find($order_detail->product_id);
         $order_info[] = (object) ['id' => $product->id, 'name' => $product->name, 'price' => $product->price, 'quantity' => $order_detail->quantity];
     }
     $data = ['order_info' => $order_info, 'order_id' => $order_id, 'message' => Session::get_flash('message'), 'remove_sure' => Session::get_flash('remove_sure')];
     return Response::forge(View::forge('user/orderDetails.tpl', $data));
 }
Пример #18
0
 public function testfree_tlds_ProductTypeIsNotHosting()
 {
     $di = new \Box_Di();
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null));
     $di['validator'] = $validatorMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model));
     $di['db'] = $dbMock;
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Servicehosting\\Service')->getMock();
     $serviceMock->expects($this->never())->method('getFreeTlds');
     $this->api->setService($serviceMock);
     $this->api->setDi($di);
     $this->setExpectedException('\\Box_Exception', 'Product type is invalid');
     $this->api->free_tlds(array('product_id' => 1));
 }
Пример #19
0
 function action_design_init()
 {
     $result['product_info'] = Model_Product::get_product_info();
     PtApp::session_start();
     $session_id = session_id();
     $design_info = self::_redis()->get("user_design_info_" . $session_id);
     if (!$design_info) {
         $design_info = array("cat_id" => 1, "product_id" => 1, "style_id" => 10, "color_count" => 0, "design_front" => null, "design_back" => null, "design_third" => null, "design_fourth" => null, "default_side" => "front");
     } else {
         $design_info = json_decode($design_info, 1);
     }
     $result['design_info'] = $design_info;
     return $result;
 }
Пример #20
0
 public function testActionCreate()
 {
     $order = new \Model_ClientOrder();
     $order->loadBean(new \RedBeanPHP\OODBBean());
     $order->product_id = rand(1, 100);
     $order->client_id = rand(1, 100);
     $order->config = 'config';
     $product = new \Model_Product();
     $product->loadBean(new \RedBeanPHP\OODBBean());
     $product->plugin = 'plugin';
     $product->plugin_config = 'plugin_config';
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('store')->will($this->returnValue(rand(1, 100)));
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($product));
     $serviceCustomModel = new \Model_ServiceCustom();
     $serviceCustomModel->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($serviceCustomModel));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $this->service->setDi($di);
     $result = $this->service->action_create($order);
     $this->assertInstanceOf('Model_ServiceCustom', $result);
 }
Пример #21
0
 /**
  * Automatically executed before the widget action. Can be used to set
  * class properties, do authorization checks, and execute other custom code.
  *
  * @return  void
  */
 public function before()
 {
     $products = new Model_Product();
     $products->where('status', '=', Model_Product::STATUS_ACTIVE);
     switch ($this->products_type) {
         case 'popular':
             $id_products = array_keys(Model_Visit::popular_products());
             if (count($id_products) > 0) {
                 $products->where('id_product', 'IN', $id_products);
             }
             break;
         case 'featured':
             $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 'latest':
         default:
             $products->order_by('created', 'desc');
             break;
     }
     $products = $products->limit($this->products_limit)->cached()->find_all();
     //die(print_r($products));
     $this->products = $products;
 }
Пример #22
0
 /**
  * Get additional content data selected
  * 
  * @param $result = Query result
  */
 public static function post_find($result)
 {
     if ($result !== null) {
         if (is_array($result)) {
             foreach ($result as $item) {
                 // It will first check if we already have result in temporary result,
                 // and only execute query if we dont. That way we dont have duplicate queries
                 // Get related products
                 $item->get_products = static::lazy_load(function () use($item) {
                     $products = Model_Product_To_Groups::find(function ($query) use($item) {
                         return $query->where('group_id', $item->id);
                     }, 'product_id');
                     if (!empty($products)) {
                         $products = '(' . implode(',', array_keys($products)) . ')';
                         return Model_Product::find(function ($query) use($products, $item) {
                             $query->where('id', 'IN', \DB::expr($products));
                             $query->order_by('sort', 'asc');
                             return $query;
                         }, 'id');
                     }
                     return array();
                 }, $item->id, 'products');
                 // Get content children
                 $item->get_children = static::lazy_load(function () use($item) {
                     return Model_Group::find(array('where' => array('parent_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'children');
                 // Get group images
                 $item->get_images = static::lazy_load(function () use($item) {
                     return Model_Group_Image::find(array('where' => array('content_id' => $item->id), 'order_by' => array('sort' => 'asc')));
                 }, $item->id, 'images');
                 // Get product groups
                 $item->get_product_groups = static::lazy_load(function () use($item) {
                     $product_groups = \Product\Model_Group::find_by_type('discount');
                     foreach ($product_groups as $product_group) {
                         $product_group->set_user_group_id($item->id);
                     }
                     return $product_groups;
                 }, $item->id, 'product_groups');
             }
         }
     }
     // return the result
     return $result;
 }
Пример #23
0
 public static function initDB()
 {
     self::$USER_TABLE = Model_User::table();
     self::$PRODUCT_TABLE = Model_Product::table();
     self::$ORDER_TABLE = Model_Order::table();
     self::$JOIN_TABLE = Model_OrderProduct::table();
     self::$CATEGORY_TABLE = Model_Category::table();
     Config::load('development/db.php');
     $which = Config::get('which');
     echo "\nwhich = {$which}\n";
     if ($which == "sqlite") {
         self::initSQLite();
     }
     $dsn = Config::get('default.connection.dsn');
     $username = Config::get('default.connection.username');
     $password = Config::get('default.connection.password');
     $cx = new PDO($dsn, $username, $password);
     self::dropAll($cx);
     self::createTables($cx, $which);
 }
Пример #24
0
 public function action_productinfo($product_id)
 {
     $change = Input::post('change');
     $quantity = Input::post('quantity');
     $cart = Session::get('cart', []);
     if (!is_null($change)) {
         $cart[$product_id] = $quantity;
         Session::set('cart', $cart);
         return Response::redirect('/cart');
     } else {
         if (isset($cart[$product_id])) {
             $quantity = $cart[$product_id];
         }
         if (is_null($quantity)) {
             $quantity = 0;
         }
     }
     $product = Model_Product::find($product_id);
     $data = ['product' => $product, 'quantity' => $quantity];
     $view = View::forge('home/productInfo.tpl', $data);
     $view->set('description', $product->description, false);
     return Response::forge($view);
 }
Пример #25
0
 /**
  * Performs an auth attempt against the database
  * @return bool
  */
 public function authenticate()
 {
     $this->_config = Zend_Registry::get('config');
     if (empty($this->_email) && empty($this->_password)) {
         $this->_code = Zend_Auth_Result::FAILURE;
         $this->_data = false;
         $this->_messages[] = $this->getMessage($this->_code);
     } else {
         // Place authentication logic here
         $authenticated = true;
         if (empty($authenticated)) {
             $this->_code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
             $this->_data = false;
             $this->_messages[] = $this->getMessage($this->_code);
         } else {
             $this->_code = Zend_Auth_Result::SUCCESS;
             $this->_data = $authenticated;
             $allProducts = Model_Product::getAll();
             $this->_messages[] = $this->getMessage($this->_code);
         }
     }
     $this->_result = new Zend_Auth_Result($this->_code, $this->_data, $this->_messages);
     return $this->_result;
 }
Пример #26
0
 public function action_index()
 {
     //template header
     $this->template->title = '';
     // $this->template->meta_keywords    = 'keywords';
     $this->template->meta_description = Core::config('general.site_name') . ' ' . __('official homepage for the online store');
     $products = new Model_Product();
     $products->where('status', '=', Model_Product::STATUS_ACTIVE);
     switch (core::config('product.products_in_home')) {
         case 3:
             $id_products = Model_Review::best_rated();
             $array_ids = array();
             foreach ($id_products as $id => $id_product) {
                 $array_ids = $id_product;
             }
             if (count($id_products) > 0) {
                 $products->where('id_product', 'IN', $array_ids);
             }
             break;
         case 2:
             $id_products = array_keys(Model_Visit::popular_products());
             if (count($id_products) > 0) {
                 $products->where('id_product', 'IN', $id_products);
             }
             break;
         case 1:
             $products->where('featured', 'IS NOT', NULL)->where('featured', '>', Date::unix2mysql())->order_by('featured', 'desc');
             break;
         case 0:
         default:
             $products->order_by('created', 'desc');
             break;
     }
     $products = $products->limit(Theme::get('num_home_products', 21))->cached()->find_all();
     $categs = Model_Category::get_category_count();
     $this->template->bind('content', $content);
     $this->template->content = View::factory('pages/home', array('products' => $products, 'categs' => $categs));
 }
Пример #27
0
 public function testaddItemm_TypeCustom()
 {
     $cartModel = new \Model_Cart();
     $cartModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel = new \Model_Product();
     $productModel->loadBean(new \RedBeanPHP\OODBBean());
     $productModel->type = 'custom';
     $data = array();
     $eventMock = $this->getMockBuilder('\\Box_EventManager')->getMock();
     $eventMock->expects($this->atLeastOnce())->method('fire');
     $serviceCustomServiceMock = $this->getMockBuilder('\\Box\\Mod\\Servicecustom\\Service')->getMock();
     $serviceCustomServiceMock->expects($this->atLeastOnce())->method('validateCustomForm')->will($this->returnValue(array()));
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Cart\\Service')->setMethods(array('isRecurrentPricing', 'isStockAvailable'))->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('isRecurrentPricing')->will($this->returnValue(false));
     $serviceMock->expects($this->atLeastOnce())->method('isStockAvailable')->will($this->returnValue(true));
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('toArray')->will($this->returnValue(array()));
     $cartProduct = new \Model_CartProduct();
     $cartProduct->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock->expects($this->atLeastOnce())->method('dispense')->will($this->returnValue($cartProduct));
     $dbMock->expects($this->atLeastOnce())->method('store');
     $di = new \Box_Di();
     $di['events_manager'] = $eventMock;
     $di['mod_service'] = $di->protect(function ($name) use($serviceCustomServiceMock) {
         return $serviceCustomServiceMock;
     });
     $di['logger'] = new \Box_Log();
     $di['db'] = $dbMock;
     $di['array_get'] = $di->protect(function (array $array, $key, $default = null) use($di) {
         return isset($array[$key]) ? $array[$key] : $default;
     });
     $serviceMock->setDi($di);
     $productModel->setDi($di);
     $result = $serviceMock->addItem($cartModel, $productModel, $data);
     $this->assertTrue($result);
 }
Пример #28
0
 /**
  * Edit product infotabs
  * 
  * @param $product_id	= Product ID
  * @param $infotab_id	= Infotab ID
  * @param $hotspot_id	= Hotspot ID
  * 
  */
 public function action_infotab_edit($produt_id = false, $infotab_id = false, $hotspot_id = false)
 {
     // Check for product
     if (!is_numeric($produt_id)) {
         \Response::redirect('admin/product/list');
     }
     // Get news item to edit
     if (!($product = Model_Product::find_one_by_id($produt_id))) {
         \Response::redirect('admin/product/list');
     }
     // Check for infotab
     if (!is_numeric($infotab_id)) {
         \Response::redirect('admin/product/list');
     }
     // Get news item to edit
     if (!($item = Model_Product_To_Infotabs::find_by_pk($infotab_id))) {
         \Response::redirect('admin/product/list');
     }
     // Get hotspot is exist
     if (is_numeric($hotspot_id)) {
         if (!($hotspot = Model_Infotab_Image::find_by_pk($hotspot_id))) {
             unset($hotspot);
         }
     }
     if (\Input::post()) {
         $val = Model_Product_To_Infotabs::validate('update', $item->type);
         // Upload image and display errors if there are any
         $image = $this->upload_infotab_image();
         if (!$image['exists'] && \Config::get('infotab.image.required', false) && empty($item->images)) {
             // No previous images and image is not selected and it is required
             \Messages::error('<strong>There was an error while trying to upload infotab image</strong>');
             \Messages::error('You have to select image');
         } elseif ($image['errors']) {
             \Messages::error('<strong>There was an error while trying to upload infotab image</strong>');
             foreach ($image['errors'] as $error) {
                 \Messages::error($error);
             }
         }
         if ($val->run() && $image['is_valid'] && !(!$image['exists'] && \Config::get('infotab.image.required', false) && empty($item->images))) {
             /** IMAGES **/
             // Get all alt texts to update if there is no image change
             foreach (\Arr::filter_prefixed(\Input::post(), 'alt_text_') as $image_id => $alt_text) {
                 if (strpos($image_id, 'new_') === false) {
                     $item_images[$image_id] = array('id' => $image_id, 'data' => array('alt_text' => \Input::post('alt_text_' . $image_id, '')));
                 }
             }
             // Save images if new files are submitted
             if (isset($this->_infotab_image_data)) {
                 foreach ($this->_infotab_image_data as $image_data) {
                     $cover_count = count($item->images);
                     if (strpos($image_data['field'], 'new_') === false) {
                         // Update existing image
                         if (str_replace('image_', '', $image_data['field']) != 0) {
                             $image_id = (int) str_replace('image_', '', $image_data['field']);
                             $cover_count--;
                             $item_images[$image_id] = array('id' => $image_id, 'data' => array('infotab_id' => $item->unique_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_' . $image_id, '')));
                             $this->delete_infotab_image(\Input::post('image_db_' . $image_id, ''));
                         }
                     } else {
                         // Save new image
                         $image_tmp = str_replace('image_new_', '', $image_data['field']);
                         $item_images[0] = array('id' => 0, 'data' => array('infotab_id' => $item->unique_id, 'image' => $image_data['saved_as'], 'alt_text' => \Input::post('alt_text_new_' . $image_tmp, ''), 'cover' => $cover_count == 0 ? 1 : 0, 'sort' => $cover_count + 1));
                     }
                 }
             }
             Model_Infotab::bind_images($item_images);
             /** END OF IMAGES **/
             // Get POST values
             $insert = \Input::post();
             // Prep some values
             $insert['description'] = trim($insert['description']);
             $insert['active'] = !empty($insert['description']) ? 1 : 0;
             $item->set($insert);
             try {
                 $item->save();
                 \Messages::success('Infotab successfully updated.');
                 \Response::redirect(\Input::post('exit', false) ? \Uri::create('admin/product/infotab_list/' . $product->id) : \Uri::admin('current'));
             } catch (\Database_Exception $e) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to update infotab</strong>');
                 // Uncomment lines below to show database errors
                 //$errors = $e->getMessage();
                 //\Messages::error($errors);
             }
         } else {
             // Delete uploaded images if there is product saving error
             if (isset($this->_infotab_image_data)) {
                 foreach ($this->_infotab_image_data as $image_data) {
                     $this->delete_infotab_image($image_data['saved_as']);
                 }
             }
             if ($val->error() != array()) {
                 // show validation errors
                 \Messages::error('<strong>There was an error while trying to update infotab</strong>');
                 foreach ($val->error() as $e) {
                     \Messages::error($e->get_message());
                 }
             }
         }
     }
     $item = Model_Product_To_Infotabs::find_by_pk($infotab_id);
     $theme_partial = \Theme::instance()->set_partial('content', $this->view_dir . 'infotabs_edit_' . strtolower($item->type))->set('product', $product)->set('infotab', $item);
     if (isset($hotspot)) {
         $theme_partial->set('hotspot', $hotspot);
     }
 }
Пример #29
0
 public function testdelete()
 {
     $data = array('id' => 1);
     $model = new \Model_Product();
     $model->loadBean(new \RedBeanPHP\OODBBean());
     $dbMock = $this->getMockBuilder('\\Box_Database')->getMock();
     $dbMock->expects($this->atLeastOnce())->method('getExistingModelById')->will($this->returnValue($model));
     $serviceMock = $this->getMockBuilder('\\Box\\Mod\\Product\\Service')->getMock();
     $serviceMock->expects($this->atLeastOnce())->method('deleteProduct')->will($this->returnValue(true));
     $di = new \Box_Di();
     $di['db'] = $dbMock;
     $validatorMock = $this->getMockBuilder('\\Box_Validate')->disableOriginalConstructor()->getMock();
     $validatorMock->expects($this->atLeastOnce())->method('checkRequiredParamsForArray')->will($this->returnValue(null));
     $di['validator'] = $validatorMock;
     $this->api->setService($serviceMock);
     $this->api->setDi($di);
     $result = $this->api->delete($data);
     $this->assertInternalType('bool', $result);
     $this->assertTrue($result);
 }
Пример #30
0
<?php

/* TODO: Add code here */
require 'config/globalconfig.php';
include_once 'class/model_product.php';
include_once 'class/model_property.php';
include_once 'class/model_productproperty.php';
include_once 'class/model_propertygroup.php';
include_once 'class/model_productprice.php';
include_once 'class/model_articletype.php';
include_once 'class/model_retailer.php';
include_once 'class/model_status.php';
include_once 'class/model_city.php';
$objProduct = new Model_Product($objConnection);
$objProperty = new Model_Property($objConnection);
$objProductProperty = new Model_ProductProperty($objConnection);
$objPropertyGroup = new Model_PropertyGroup($objConnection);
$objProductPrice = new Model_ProductPrice($objConnection);
$objArticleType = new Model_ArticleType($objConnection);
$objRetailer = new Model_Retailer($objConnection);
if ($_pgR["act"] == Model_Product::ACT_ADD || $_pgR["act"] == Model_Product::ACT_UPDATE) {
    if (global_common::isCLogin()) {
        //get user info
        $c_userInfo = $_SESSION[global_common::SES_C_USERINFO];
        $properties = $_pgR['Properties'];
        //$properties = html_entity_decode($properties,ENT_COMPAT ,'UTF-8' );
        $productName = $_pgR['ProductName'];
        $productName = html_entity_decode($productName, ENT_COMPAT, 'UTF-8');
        $catalogueID = $_pgR['CatalogueID'];
        $catalogueID = html_entity_decode($catalogueID, ENT_COMPAT, 'UTF-8');
        $imageLink = $_pgR['ImageLink'];