-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
234ef9f
commit f6eb1aa
Showing
14 changed files
with
722 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.