public function testUpdate() { $setting = Subbly::api('subbly.setting')->all()->take(1)->toArray(); $settingValue = reset($setting); $settingKey = key($setting); /** * NOT OK */ // "setting" not defined $response = $this->callJSON('PATCH', "/api/v1/settings/{$settingKey}"); $this->assertResponseStatus(400); $this->assertResponseJSONValid(); $json = $this->getJSONContent(); $this->assertObjectHasAttribute('error', $json->response); /** * OK */ $settingKey = 'test.subbly.string_setting'; // Test with string setting and with wrong array value $response = $this->callJSON('PATCH', "/api/v1/settings/{$settingKey}", array('value' => array())); $this->assertResponseStatus(400); $this->assertResponseJSONValid(); $json = $this->getJSONContent(); $this->assertObjectHasAttribute('error', $json->response); // "settings" with datas $value = TestCase::faker()->word; $response = $this->callJSON('PATCH', "/api/v1/settings/{$settingKey}", array('value' => $value)); $this->assertResponseOk(); $this->assertResponseJSONValid(); // $json = $this->getJSONContent(); }
/** * Execute the helper * {{CartHelper}} * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $buffer = ''; $cart = \Subbly\Subbly::api('subbly.cart')->content()->toArray(); if (!$cart) { $template->setStopToken('else'); $template->discard(); $template->setStopToken(false); $buffer = $template->render($context); } elseif (is_array($cart) || $cart instanceof \Traversable) { $isList = is_array($cart) && array_keys($cart) === range(0, count($cart) - 1); $index = 0; $lastIndex = $isList ? count($cart) - 1 : false; foreach ($cart as $key => $var) { $specialVariables = array('@index' => $index, '@first' => $index === 0, '@last' => $index === $lastIndex); if (!$isList) { $specialVariables['@key'] = $key; } $context->pushSpecialVariables($specialVariables); $context->push($var); $template->setStopToken('else'); $template->rewind(); $buffer .= $template->render($context); $context->pop(); $context->popSpecialVariables(); $index++; } $template->setStopToken(false); } return $buffer; }
/** * Set Product order. * * @route POST /api/v1/products/{sku}/images/sort * @authentication required */ public function sort($product_sku) { if (!Input::has('sortable')) { return $this->jsonErrorResponse('"sortable" is required.'); } $images = Subbly::api('subbly.product_image')->sort(Input::get('sortable')); return $this->jsonResponse(array(), array('status' => array('message' => 'Product updated'))); }
/** * Update a Product * * @route PUT|PATCH /api/v1/products/:sku * @authentication required */ public function update($sku) { if (!Input::has('product')) { return $this->jsonErrorResponse('"product" is required.'); } $product = Subbly::api('subbly.product')->update($sku, Input::get('product')); return $this->jsonResponse(array('product' => $product), array('status' => array('message' => 'Product updated'))); }
/** * Update a Setting * * @route PUT|PATCH /api/settings/{setting_key} * @authentication required */ public function update($setting_key) { if (!Input::has('value')) { return $this->jsonErrorResponse('"value" is required.'); } $user = Subbly::api('subbly.setting')->update($setting_key, Input::get('value')); return $this->jsonResponse(array(), array('status' => array('code' => 200, 'message' => 'Setting updated'))); }
/** * Update a User. * * @route PUT|PATCH /api/v1/users/:uid * @authentication required */ public function update($uid) { if (!Input::has('user')) { return $this->jsonErrorResponse('"user" is required.'); } $user = Subbly::api('subbly.user')->update($uid, Input::get('user')); return $this->jsonResponse(array('user' => $this->presenter->single($user)), array('status' => array('code' => 200, 'message' => 'User updated'))); }
/** * Update a Order. * * @route PUT|PATCH /api/v1/orders/:id * @authentication required */ public function update($sku) { if (!Input::has('order')) { return $this->jsonErrorResponse('"order" is required.'); } $order = Subbly::api('subbly.order')->update($sku, Input::get('order')); return $this->jsonResponse(array('order' => $this->presenter->single($order)), array('status' => array('message' => 'Order updated'))); }
public function showWelcome() { // Subbly\Subbly::init(); // echo Config::get('subbly.backendUri', 'backend'); $credentials = array('login' => '*****@*****.**', 'password' => 'michael'); $authenticated = Subbly::api('subbly.user')->authenticate($credentials); var_dump($authenticated); // return View::make('hello'); }
/** * Update a Setting. * * @route PUT|PATCH /api/settings * @authentication required */ public function update() { if (!Input::has('settings')) { return $this->jsonErrorResponse('"settings" is required.'); } $settings = Subbly::api('subbly.setting'); $user = $settings->updateMany(Input::get('settings')); return $this->jsonResponse(array('settings' => $settings->all()), array('status' => array('code' => 200, 'message' => 'Settings updated'))); }
/** * Execute the helper * {{CartCountHelper}} * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $buffer = ''; // $args = $template->parseArguments( $args ); // if( count( $args ) != 1 ) // throw new \InvalidArgumentException( // '"assets" helper expects exactly one argument.' // ); return Subbly::api('subbly.cart')->count(); }
/** * Get formated datas for a collection. * * @param \Subbly\Model\Collection $collection * * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $entries = new Entries(); foreach ($collection as $group) { $entry = new Entry($group); $entry->conditionalField('id', function () { return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth'); })->field('name')->field('permissions')->dateField('created_at')->dateField('updated_at'); $entries->addEntry($entry); } return $entries->toArray(); }
/** * Get formated datas for a collection. * * @param \Subbly\Model\Collection $collection * * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $entries = new Entries(); foreach ($collection as $order) { $entry = new Entry($order); $entry->conditionalField('id', function () { return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth'); })->field('uid')->field('status')->decimal('total_price', (double) $order->total_price)->integer('total_items', (int) $order->total_items)->decimal('shipping_cost', (double) $order->shipping_cost)->relationshipField('user', 'Subbly\\Presenter\\V1\\UserPresenter')->relationshipField('billing_address', 'Subbly\\Presenter\\V1\\OrderAddressPresenter')->relationshipField('shipping_address', 'Subbly\\Presenter\\V1\\OrderAddressPresenter')->relationshipField('products', 'Subbly\\Presenter\\V1\\OrderProductPresenter')->dateField('created_at')->dateField('updated_at'); $entries->addEntry($entry); } return $entries->toArray(); }
/** * Get formated datas for a collection. * * @param \Subbly\Model\Collection $collection * * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $entries = new Entries(); foreach ($collection as $userAddress) { $entry = new Entry($userAddress); $entry->conditionalField('id', function () { return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth'); })->field('uid')->field('name')->field('firstname')->field('lastname')->field('address1')->field('address2')->field('zipcode')->field('city')->field('country')->field('phone_work')->field('phone_home')->field('phone_mobile')->field('others_informations')->dateField('created_at')->dateField('updated_at'); $entries->addEntry($entry); } return $entries->toArray(); }
/** * Get formated datas for a collection. * * @param \Subbly\Model\Collection $collection * * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $entries = new Entries(); foreach ($collection as $productImage) { $entry = new Entry($productImage); $entry->conditionalField('id', function () { return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth'); })->field('filename')->field('product')->field('uid')->field('position')->dateField('created_at')->dateField('updated_at'); $entries->addEntry($entry); } return $entries->toArray(); }
/** * Get formated datas for a collection. * * @param \Subbly\Model\Collection $collection * * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $entries = new Entries(); foreach ($collection as $user) { $entry = new Entry($user); $entry->conditionalField('id', function () { return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth'); })->field('uid')->field('email')->field('firstname')->field('lastname')->compositeField('displayName', 'firstname', 'lastname')->relationshipField('addresses', 'Subbly\\Presenter\\V1\\UserAddressPresenter')->integer('orders_total', $user->countOrders())->relationshipField('orders', 'Subbly\\Presenter\\V1\\OrderPresenter')->relationshipField('groups', 'Subbly\\Presenter\\V1\\GroupPresenter')->dateField('created_at')->dateField('updated_at'); $entries->addEntry($entry); } return $entries->toArray(); }
/** * Get formated datas for a collection. * * @param \Subbly\Model\Collection $collection * * @return \Illuminate\Support\Collection */ public function collection(Collection $collection) { $entries = new Entries(); foreach ($collection as $product) { $entry = new Entry($product); $entry->conditionalField('id', function () { return Subbly::api('subbly.user')->hasAccess('subbly.backend.auth'); })->field('position')->field('name')->field('description')->field('sku')->field('status')->field('price')->field('sale_price')->field('quantity')->relationshipField('images', 'Subbly\\Presenter\\V1\\ProductImagePresenter')->relationshipField('options', 'Subbly\\Presenter\\V1\\ProductOptionPresenter')->relationshipField('categories', 'Subbly\\Presenter\\V1\\ProductCategoryPresenter')->dateField('created_at')->dateField('updated_at'); $entries->addEntry($entry); } return $entries->toArray(); }
/** * Create/Update Product's 'categories. * * @route POST/PUT /api/v1/products/:product_sku/categories * @authentication required */ private function manage($product_sku) { $product = Subbly::api('subbly.product')->find($product_sku); if (!Input::has('product_category')) { return $this->jsonErrorResponse('"product_category" is required.'); } if (!is_array(Input::get('product_category'))) { return $this->jsonErrorResponse('"product_category" must be an array.'); } Subbly::api('subbly.product_category')->create(Input::get('product_category'), $product); return $this->jsonResponse(array(), array('status' => array('code' => 201, 'message' => 'ProductCategory created'))); }
public function testApi() { $api = Subbly::api(); $this->assertInstanceOf('Subbly\\Api\\Api', $api); $service = Subbly::api('subbly.user'); $this->assertInstanceOf('Subbly\\Api\\Service\\Service', $service); $service = Subbly::api()->service('subbly.user'); $this->assertInstanceOf('Subbly\\Api\\Service\\Service', $service); try { Subbly::api('subbly.a_very_wrong_service'); $this->fail('Subbly\\Api\\Exception has not be raised.'); } catch (\Subbly\Api\Exception $e) { $this->assertTrue(true); } }
/** * Execute the helper * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $buffer = ''; $cart = \Subbly\Subbly::api('subbly.cart')->count(); if (!count($cart)) { $template->setStopToken('else'); $template->discard($context); $template->setStopToken(false); $buffer = $template->render($context); } else { $template->setStopToken('else'); $buffer = $template->render($context); $template->setStopToken(false); $template->discard($context); } return $buffer; }
/** * Execute the helper * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { // $args = $this->parseArgs( $args ); $user = $context->get('user'); if (!$user) { throw new \Exception("User need to be log-in to access to his addresses"); } // Get Address // ----------------- $options = ['where' => [['uid', '=', $user->uid]]]; try { $addresses = Subbly::api('subbly.user_address')->findByUser($user, $options); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { return false; } if (!count($addresses)) { $addresses = false; } $buffer = ''; if (!$addresses) { $template->setStopToken('else'); $template->discard(); $template->setStopToken(false); $buffer = $template->render($context); } elseif (is_array($addresses) || $addresses instanceof \Traversable) { $isList = is_array($addresses) && array_keys($addresses) === range(0, count($addresses) - 1); $index = 0; $lastIndex = $isList ? count($addresses) - 1 : false; foreach ($addresses as $key => $var) { $specialVariables = array('@index' => $index, '@first' => $index === 0, '@last' => $index === $lastIndex); if (!$isList) { $specialVariables['@key'] = $key; } $context->pushSpecialVariables($specialVariables); $context->push($var); $template->setStopToken('else'); $template->rewind(); $buffer .= $template->render($context); $context->pop(); $context->popSpecialVariables(); $index++; } $template->setStopToken(false); } return $buffer; }
/** * Execute the helper * {{#isUserLogin}} * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $tmp = Subbly::api('subbly.user')->check(); if (!$tmp) { $template->setStopToken('else'); $buffer = $template->render($context); $template->setStopToken(false); $template->discard($context); } else { $context->push(['user' => Subbly::api('subbly.user')->currentUser()]); $template->setStopToken('else'); $template->discard($context); $template->setStopToken(false); $buffer = $template->render($context); } $context->pop(); return $buffer; }
/** * Execute the helper * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $props = $this->parseProps($args, $context); $args = $this->parseArgs($args); $field = 'id'; $id = false; $buffer = ''; // no properties // so product's ID is in URL // or is th first arguments if (!$props) { $id = count($args) === 0 ? $context->get('inputs.productId') : $args[0]; } else { if (array_key_exists('productId', $props)) { $id = $props['productId']; } else { if (array_key_exists('productSku', $props)) { $id = $props['productSku']; $field = 'sku'; } } } if (!$id) { throw new \InvalidArgumentException('Can not find product identifier'); } // Product query // ---------------- // TODO: add status restriction if // current user is not loggued to Backend $productOptions = ['includes' => ['images', 'categories', 'options', 'translations'], 'where' => [['status', '!=', 'draft'], ['status', '!=', 'hidden']]]; // Get product // ----------------- try { $product = \Subbly\Subbly::api('subbly.product')->find($id, $productOptions, $field)->toArray(); } catch (\Exception $e) { throw new \InvalidArgumentException($e->getMessage()); } $context->push($product); $template->rewind(); $buffer .= $template->render($context); $context->pop(); return $buffer; }
/** * Execute the helper * * @param \Handlebars\Template $template The template instance * @param \Handlebars\Context $context The current context * @param array $args The arguments passed the the helper * @param string $source The source * * @return mixed */ public function execute(Template $template, Context $context, $args, $source) { $isLogin = $context->get('isUserLogin'); if (!$isLogin) { throw new \Exception("User need to be log-in to access to his addresses"); } $props = $this->parseProps($args, $context); $args = $this->parseArgs($args); $id = false; $buffer = ''; // no properties // so address's ID is in URL // or is th first arguments if (!$props) { $id = count($args) === 0 ? $context->get('inputs.addressId') : $args[0]; } else { if (array_key_exists('addressId', $props)) { $id = $props['addressId']; } } // new address if (!$id) { return $template->render($context); } // throw new \InvalidArgumentException( 'Can not find user address ID'); // Get Address // ----------------- $user = $context->get('user'); try { $options = ['where' => [['uid', '=', $user->uid]]]; $address = Subbly::api('subbly.user_address')->find($id, $options)->toArray(); } catch (\Illuminate\Database\Eloquent\ModelNotFoundException $e) { throw new \InvalidArgumentException($e->getMessage()); } $buffer = ''; $context->push($address); $template->rewind(); $buffer .= $template->render($context); $context->pop(); return $buffer; }
private function getService() { return Subbly::api('subbly.product_image'); }
/** * Create a new Order. * * @example * $order = Subbly\Model\Order; * Subbly::api('subbly.order')->create($order); * * Subbly::api('subbly.order')->create(array( * 'firstname' => 'Jon', * 'lastname' => 'Snow', * )); * * @param \Subbly\Model\Order|array $order * * @return \Subbly\Model\Order * * @api */ public function create($order, $cart, $shipping, $billing = null) { if (is_array($order)) { $order = new Order($order); } if ($order instanceof Order) { if ($this->fireEvent('creating', array($order)) === false) { return false; } $order->setCaller($this); \DB::transaction(function () use($order, $cart, $shipping, $billing) { $shipping = \Subbly\Subbly::api('subbly.orderaddress')->create($shipping); $order->shipping_address_id = $shipping->id; if ($billing) { $billing = \Subbly\Subbly::api('subbly.orderaddress')->create($billing); $order->billing_address_id = $billing->id; } $order->save(); foreach ($cart as $item) { // TODO: add product sku, name and description in current locale. // work as cache if product is not available later $product = ['order_id' => $order->id, 'product_id' => $item['id'], 'price' => $item['price'], 'name' => $item['name'], 'sku' => $item['sku'], 'sale_price' => 0, 'quantity' => $item['qty'], 'options' => json_encode($item['options'])]; $ret = \Subbly\Subbly::api('subbly.orderproduct')->create($product); } }); $this->fireEvent('created', array($order)); // $order = $this->find($order->id); return $order; } throw new Exception(sprintf(Exception::CANT_CREATE_MODEL, 'Subbly\\Model\\Order', $this->name())); }
private function getService() { return Subbly::api('subbly.setting'); }
/** * */ protected function getCurrentUser() { return Subbly::api('subbly.user')->currentUser(); }
public function run() { Subbly::api('subbly.setting')->registerDefaultSettings(__DIR__ . '/../../configs/default_settings.yml'); Subbly::api('subbly.setting')->all(); }
/** * Delete a UserAddress. * * @route DELETE /api/v1/users/:user_uid/addresses/:uid * @authentication required */ public function delete($user_uid, $uid) { $user = Subbly::api('subbly.user')->find($user_uid); $userAddress = Subbly::api('subbly.user_address')->delete($uid); return $this->jsonResponse(array('user_address' => $userAddress), array('status' => array('code' => 200, 'message' => 'UserAddress deleted'))); }
private function getService() { return Subbly::api('subbly.order'); }