Skip to content

Commit

Permalink
fix: fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrdrvn committed Sep 22, 2021
1 parent 234ef9f commit f6eb1aa
Show file tree
Hide file tree
Showing 14 changed files with 722 additions and 5 deletions.
2 changes: 0 additions & 2 deletions Model/Api/Model/Common/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use \Vuefront\Vuefront\Model\Api\System\Engine\Model;
use Magefan\Blog\Model\Url;


class Seo extends Model
{
private $_categoryFactory;
Expand Down
1 change: 0 additions & 1 deletion Model/Api/Model/Common/Vuefront.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public function editApp($name, $appSetting)
{
$appSetting['codename'] = $name;


$app = $this->_appsFactory->create()->getCollection();
$app->addFieldToSelect('*');
$app->addFieldToFilter('codename', ['like' => $name]);
Expand Down
119 changes: 119 additions & 0 deletions Model/Api/Model/Store/Cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

namespace Vuefront\Vuefront\Model\Api\Model\Store;

use \Vuefront\Vuefront\Model\Api\System\Engine\Model;

class Cart extends Model
{

private $_currencyHelper;

/**
* @var \Magento\Downloadable\Api\LinkRepositoryInterface
*/
private $_linkRepository;

/**
* @var \Magento\Checkout\Model\Cart
*/
private $_cartModel;

/**
* @var \Magento\Quote\Model\Quote
*/
private $_quoteModel;

private $_sessionFactory;

public function __construct(
\Magento\Framework\Pricing\Helper\Data $currencyHelper,
\Magento\Checkout\Model\Cart $cartModel,
\Magento\Downloadable\Api\LinkRepositoryInterface $linkRepository,
\Magento\Customer\Model\Session $sessionFactory,
\Magento\Quote\Model\Quote $quoteFactory
) {
$this->_currencyHelper = $currencyHelper;
$this->_cartModel = $cartModel;
$this->_linkRepository = $linkRepository;
$this->_sessionFactory = $sessionFactory;
$this->_quoteModel = $quoteFactory;
}//end __construct()

public function prepareCart()
{
$cart = [];
$this->_cartModel->getQuote()->collectTotals();
$cart = [
'products' => [],
'total' => $this->currency->format($this->_cartModel->getQuote()->getGrandTotal()),
];

$results = $this->_cartModel->getItems();

foreach ($results as $value) {
/*
@var \Magento\Catalog\Model\Product $product
*/
$product = $value->getProduct();
if (!$value->isDeleted() && !$value->getParentItemId() && !$value->getParentItem()) {
$price = "";
if ($product->getTypeId() != "simple") {
$price = $this->_currencyHelper->currency($product->getFinalPrice(), true, false);
} else {
$price = $this->_currencyHelper->currency($product->getPrice(), true, false);
}
$cart['products'][] = [
'key' => $value->getId(),
'product' => [
'product_id' => $product->getId(),
'price' => $price
],
'quantity' => $value->getQty(),
'option' => $this->getCartOptions($product, $value),
'total' => $this->currency->format($value->getPrice() * $value->getQty()),
];
}
}

return $cart;
}

public function getProduct($key)
{
$product = null;

foreach ($this->cart->getProducts() as $value) {
if ($value['cart_id'] == $key) {
$product = $value;
break;
}
}
if ($product === null) {
return null;
}

return $product;
}

/**
* @param $product \Magento\Catalog\Model\Product
* @param $value mixed
* @return array
*/
public function getCartOptions($product, $value)
{
$options = [];
$result_options = $product->getTypeInstance(true)->getOrderOptions($product);

if (!empty($result_options['attributes_info'])) {
foreach ($result_options['attributes_info'] as $option) {
$options[] = [
'option_id' => (int)$option['option_id'],
'option_value_id' => (int)$option['option_value'],
];
}
}
return $options;
}
}
2 changes: 1 addition & 1 deletion Model/Api/Model/Store/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function getCategories($data = [])
}

if ($data['top']) {
$collection->addAttributeToFilter('include_in_menu', array('eq' => $data['top'] ? 1 : 0));
$collection->addAttributeToFilter('include_in_menu', ['eq' => $data['top'] ? 1 : 0]);
}

if ($data['size'] != '-1') {
Expand Down
1 change: 0 additions & 1 deletion Model/Api/Resolver/Store/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function __construct(
$this->_linkRepository = $linkRepository;
$this->_sessionFactory = $sessionFactory;
$this->_quoteModel = $quoteFactory;

}//end __construct()

public function add($args)
Expand Down
12 changes: 12 additions & 0 deletions Model/ResourceModel/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Vuefront\Vuefront\Model\ResourceModel;

class Settings extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
{

protected function _construct()
{
$this->_init('vuefront_settings', 'setting_id');
}
}
15 changes: 15 additions & 0 deletions Model/ResourceModel/Settings/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Vuefront\Vuefront\Model\ResourceModel\Settings;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
protected function _construct()
{
parent::_construct();
$this->_init(
\Vuefront\Vuefront\Model\Settings::class,
\Vuefront\Vuefront\Model\ResourceModel\Settings::class
);
}
}
11 changes: 11 additions & 0 deletions Model/Settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Vuefront\Vuefront\Model;

class Settings extends \Magento\Framework\Model\AbstractModel
{
protected function _construct()
{
$this->_init(\Vuefront\Vuefront\Model\ResourceModel\Settings::class);
}
}
74 changes: 74 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace Vuefront\Vuefront\Setup;

use \Magento\Framework\Setup\SchemaSetupInterface;
use \Magento\Framework\Setup\ModuleContextInterface;
use \Magento\Framework\Setup\UpgradeSchemaInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
{

$installer = $setup;

$connection = $installer->getConnection();

$installer->startSetup();
if (version_compare($context->getVersion(), '1.0.0', '<')) {
$table = $setup->getTable('vuefront_apps');
$connection->addColumn(
$setup->getTable($table),
'eventUrl',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
'nullable' => true,
'comment' => 'Url for events'
]
);
$connection->addColumn(
$setup->getTable($table),
'authUrl',
[
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => 255,
['nullable' => true],
'comment' => 'Url for auth'
]
);

if ($connection->isTableExists('vuefront_settings') == false) {

/**
* Create table 'vuefront_settings'
*/
$table = $installer->getConnection()->newTable(
$installer->getTable('vuefront_settings')
)->addColumn(
'setting_id',
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
null,
['identity' => true, 'nullable' => false, 'primary' => true],
'SETTING ID'
)->addColumn(
'key',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
255,
['nullable' => true],
'SETTING key'
)->addColumn(
'value',
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'64k',
['nullable' => true],
'SETTING value'
);
$installer->getConnection()->createTable($table);
}
}

$installer->endSetup();
}
}
51 changes: 51 additions & 0 deletions etc/schemaAdmin.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
type CustomerResult {
content: [Customer]
first: Boolean
last: Boolean
number: Int
numberOfElements: Int
size: Int
totalPages: Int
totalElements: Int
}
type OptionResult {
content: [Option]
first: Boolean
last: Boolean
number: Int
numberOfElements: Int
size: Int
totalPages: Int
totalElements: Int
}

type Option {
id: String
name: String
type: String
sort_order: Int
values: [OptionValue]
}

input InputAppSetting {
eventUrl: String
jwt: String
authUrl: String
}

type AppSetting {
codename: String
authUrl: String
eventUrl: String
jwt: String
}

type RootQueryType {
customersList(page: Int = 1, size: Int = 10, search: String, sort: String = "email", order: String = "ASC"): CustomerResult
customer(id: String): Customer
option(id: String): Option
optionsList(page: Int = 1, size: Int = 10, search: String, sort: String = "sort_order", order: String = "ASC"): OptionResult
}
type RootMutationType {
updateApp(name: String, settings: InputAppSetting): AppSetting
}
Loading

0 comments on commit f6eb1aa

Please sign in to comment.