Skip to content

Commit f6eb1aa

Browse files
committed
fix: fix bugs
1 parent 234ef9f commit f6eb1aa

File tree

14 files changed

+722
-5
lines changed

14 files changed

+722
-5
lines changed

Model/Api/Model/Common/Seo.php

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use \Vuefront\Vuefront\Model\Api\System\Engine\Model;
66
use Magefan\Blog\Model\Url;
7-
8-
97
class Seo extends Model
108
{
119
private $_categoryFactory;

Model/Api/Model/Common/Vuefront.php

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function editApp($name, $appSetting)
2626
{
2727
$appSetting['codename'] = $name;
2828

29-
3029
$app = $this->_appsFactory->create()->getCollection();
3130
$app->addFieldToSelect('*');
3231
$app->addFieldToFilter('codename', ['like' => $name]);

Model/Api/Model/Store/Cart.php

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model\Api\Model\Store;
4+
5+
use \Vuefront\Vuefront\Model\Api\System\Engine\Model;
6+
7+
class Cart extends Model
8+
{
9+
10+
private $_currencyHelper;
11+
12+
/**
13+
* @var \Magento\Downloadable\Api\LinkRepositoryInterface
14+
*/
15+
private $_linkRepository;
16+
17+
/**
18+
* @var \Magento\Checkout\Model\Cart
19+
*/
20+
private $_cartModel;
21+
22+
/**
23+
* @var \Magento\Quote\Model\Quote
24+
*/
25+
private $_quoteModel;
26+
27+
private $_sessionFactory;
28+
29+
public function __construct(
30+
\Magento\Framework\Pricing\Helper\Data $currencyHelper,
31+
\Magento\Checkout\Model\Cart $cartModel,
32+
\Magento\Downloadable\Api\LinkRepositoryInterface $linkRepository,
33+
\Magento\Customer\Model\Session $sessionFactory,
34+
\Magento\Quote\Model\Quote $quoteFactory
35+
) {
36+
$this->_currencyHelper = $currencyHelper;
37+
$this->_cartModel = $cartModel;
38+
$this->_linkRepository = $linkRepository;
39+
$this->_sessionFactory = $sessionFactory;
40+
$this->_quoteModel = $quoteFactory;
41+
}//end __construct()
42+
43+
public function prepareCart()
44+
{
45+
$cart = [];
46+
$this->_cartModel->getQuote()->collectTotals();
47+
$cart = [
48+
'products' => [],
49+
'total' => $this->currency->format($this->_cartModel->getQuote()->getGrandTotal()),
50+
];
51+
52+
$results = $this->_cartModel->getItems();
53+
54+
foreach ($results as $value) {
55+
/*
56+
@var \Magento\Catalog\Model\Product $product
57+
*/
58+
$product = $value->getProduct();
59+
if (!$value->isDeleted() && !$value->getParentItemId() && !$value->getParentItem()) {
60+
$price = "";
61+
if ($product->getTypeId() != "simple") {
62+
$price = $this->_currencyHelper->currency($product->getFinalPrice(), true, false);
63+
} else {
64+
$price = $this->_currencyHelper->currency($product->getPrice(), true, false);
65+
}
66+
$cart['products'][] = [
67+
'key' => $value->getId(),
68+
'product' => [
69+
'product_id' => $product->getId(),
70+
'price' => $price
71+
],
72+
'quantity' => $value->getQty(),
73+
'option' => $this->getCartOptions($product, $value),
74+
'total' => $this->currency->format($value->getPrice() * $value->getQty()),
75+
];
76+
}
77+
}
78+
79+
return $cart;
80+
}
81+
82+
public function getProduct($key)
83+
{
84+
$product = null;
85+
86+
foreach ($this->cart->getProducts() as $value) {
87+
if ($value['cart_id'] == $key) {
88+
$product = $value;
89+
break;
90+
}
91+
}
92+
if ($product === null) {
93+
return null;
94+
}
95+
96+
return $product;
97+
}
98+
99+
/**
100+
* @param $product \Magento\Catalog\Model\Product
101+
* @param $value mixed
102+
* @return array
103+
*/
104+
public function getCartOptions($product, $value)
105+
{
106+
$options = [];
107+
$result_options = $product->getTypeInstance(true)->getOrderOptions($product);
108+
109+
if (!empty($result_options['attributes_info'])) {
110+
foreach ($result_options['attributes_info'] as $option) {
111+
$options[] = [
112+
'option_id' => (int)$option['option_id'],
113+
'option_value_id' => (int)$option['option_value'],
114+
];
115+
}
116+
}
117+
return $options;
118+
}
119+
}

Model/Api/Model/Store/Category.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getCategories($data = [])
3333
}
3434

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

3939
if ($data['size'] != '-1') {

Model/Api/Resolver/Store/Cart.php

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ public function __construct(
5454
$this->_linkRepository = $linkRepository;
5555
$this->_sessionFactory = $sessionFactory;
5656
$this->_quoteModel = $quoteFactory;
57-
5857
}//end __construct()
5958

6059
public function add($args)

Model/ResourceModel/Settings.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model\ResourceModel;
4+
5+
class Settings extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
6+
{
7+
8+
protected function _construct()
9+
{
10+
$this->_init('vuefront_settings', 'setting_id');
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model\ResourceModel\Settings;
4+
5+
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
6+
{
7+
protected function _construct()
8+
{
9+
parent::_construct();
10+
$this->_init(
11+
\Vuefront\Vuefront\Model\Settings::class,
12+
\Vuefront\Vuefront\Model\ResourceModel\Settings::class
13+
);
14+
}
15+
}

Model/Settings.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model;
4+
5+
class Settings extends \Magento\Framework\Model\AbstractModel
6+
{
7+
protected function _construct()
8+
{
9+
$this->_init(\Vuefront\Vuefront\Model\ResourceModel\Settings::class);
10+
}
11+
}

Setup/UpgradeSchema.php

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Setup;
4+
5+
use \Magento\Framework\Setup\SchemaSetupInterface;
6+
use \Magento\Framework\Setup\ModuleContextInterface;
7+
use \Magento\Framework\Setup\UpgradeSchemaInterface;
8+
9+
class UpgradeSchema implements UpgradeSchemaInterface
10+
{
11+
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
12+
{
13+
14+
$installer = $setup;
15+
16+
$connection = $installer->getConnection();
17+
18+
$installer->startSetup();
19+
if (version_compare($context->getVersion(), '1.0.0', '<')) {
20+
$table = $setup->getTable('vuefront_apps');
21+
$connection->addColumn(
22+
$setup->getTable($table),
23+
'eventUrl',
24+
[
25+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
26+
'length' => 255,
27+
'nullable' => true,
28+
'comment' => 'Url for events'
29+
]
30+
);
31+
$connection->addColumn(
32+
$setup->getTable($table),
33+
'authUrl',
34+
[
35+
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
36+
'length' => 255,
37+
['nullable' => true],
38+
'comment' => 'Url for auth'
39+
]
40+
);
41+
42+
if ($connection->isTableExists('vuefront_settings') == false) {
43+
44+
/**
45+
* Create table 'vuefront_settings'
46+
*/
47+
$table = $installer->getConnection()->newTable(
48+
$installer->getTable('vuefront_settings')
49+
)->addColumn(
50+
'setting_id',
51+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
52+
null,
53+
['identity' => true, 'nullable' => false, 'primary' => true],
54+
'SETTING ID'
55+
)->addColumn(
56+
'key',
57+
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
58+
255,
59+
['nullable' => true],
60+
'SETTING key'
61+
)->addColumn(
62+
'value',
63+
\Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
64+
'64k',
65+
['nullable' => true],
66+
'SETTING value'
67+
);
68+
$installer->getConnection()->createTable($table);
69+
}
70+
}
71+
72+
$installer->endSetup();
73+
}
74+
}

etc/schemaAdmin.graphql

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
type CustomerResult {
2+
content: [Customer]
3+
first: Boolean
4+
last: Boolean
5+
number: Int
6+
numberOfElements: Int
7+
size: Int
8+
totalPages: Int
9+
totalElements: Int
10+
}
11+
type OptionResult {
12+
content: [Option]
13+
first: Boolean
14+
last: Boolean
15+
number: Int
16+
numberOfElements: Int
17+
size: Int
18+
totalPages: Int
19+
totalElements: Int
20+
}
21+
22+
type Option {
23+
id: String
24+
name: String
25+
type: String
26+
sort_order: Int
27+
values: [OptionValue]
28+
}
29+
30+
input InputAppSetting {
31+
eventUrl: String
32+
jwt: String
33+
authUrl: String
34+
}
35+
36+
type AppSetting {
37+
codename: String
38+
authUrl: String
39+
eventUrl: String
40+
jwt: String
41+
}
42+
43+
type RootQueryType {
44+
customersList(page: Int = 1, size: Int = 10, search: String, sort: String = "email", order: String = "ASC"): CustomerResult
45+
customer(id: String): Customer
46+
option(id: String): Option
47+
optionsList(page: Int = 1, size: Int = 10, search: String, sort: String = "sort_order", order: String = "ASC"): OptionResult
48+
}
49+
type RootMutationType {
50+
updateApp(name: String, settings: InputAppSetting): AppSetting
51+
}

0 commit comments

Comments
 (0)