Skip to content

Commit 234ef9f

Browse files
committed
feat: update for new version vuefront
1 parent 112719b commit 234ef9f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+6662
-4831
lines changed

Model/Api/Model/Common/Customer.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model\Api\Model\Common;
4+
5+
use \Vuefront\Vuefront\Model\Api\System\Engine\Model;
6+
7+
class Customer extends Model
8+
{
9+
private $_collectionFactory;
10+
private $_customerFactory;
11+
12+
public function __construct(
13+
\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory,
14+
\Magento\Customer\Model\Customer $customerFactory
15+
) {
16+
$this->_collectionFactory = $collectionFactory;
17+
$this->_customerFactory = $customerFactory;
18+
}
19+
20+
public function getCustomer($customer_id)
21+
{
22+
return $this->_customerFactory->create()->load($customer_id);
23+
}
24+
25+
public function getCustomers($data)
26+
{
27+
/** @var $collection \Magento\Customer\Model\ResourceModel\Customer\Collection */
28+
$collection = $this->_collectionFactory->create();
29+
30+
if (!empty($data['search'])) {
31+
$collection->addFieldToFilter([
32+
['attribute'=>'firstname', 'like' => '%' . $data['search'] . '%'],
33+
['attribute'=>'lastname', 'like' => '%' . $data['search'] . '%'],
34+
]);
35+
}
36+
37+
if ($data['size'] != '-1') {
38+
$collection->setPageSize($data['size']);
39+
$collection->setCurPage($data['page']);
40+
}
41+
42+
if (isset($data['order']) && ($data['order'] == 'DESC')) {
43+
$order = "DESC";
44+
} else {
45+
$order = "ASC";
46+
}
47+
48+
$sort_data = [
49+
'id' => 'entity_id',
50+
'sort_order' => 'position'
51+
];
52+
53+
if (isset($data['sort']) && in_array($data['sort'], array_keys($sort_data))) {
54+
$sort = $sort_data[$data['sort']];
55+
} else {
56+
$sort = "entity_id";
57+
}
58+
59+
$collection->setOrder($sort, $order);
60+
$collection->load();
61+
62+
return $collection;
63+
}
64+
}

Model/Api/Model/Common/Seo.php

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model\Api\Model\Common;
4+
5+
use \Vuefront\Vuefront\Model\Api\System\Engine\Model;
6+
use Magefan\Blog\Model\Url;
7+
8+
9+
class Seo extends Model
10+
{
11+
private $_categoryFactory;
12+
private $_categoryCollectionFactory;
13+
private $_blogCategoryCollectionFactory;
14+
private $_pageCollectionFactory;
15+
private $_postCollectionFactory;
16+
private $_productCollectionFactory;
17+
private $_manufacturerCollectionFactory;
18+
private $_scopeConfig;
19+
private $_suffix;
20+
private $_url;
21+
22+
public function __construct(
23+
\Magento\Catalog\Model\CategoryFactory $categoryFactory,
24+
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
25+
\Magento\Cms\Model\ResourceModel\Page\CollectionFactory $pageCollectionFactory,
26+
\Magefan\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory,
27+
\Magefan\Blog\Model\ResourceModel\Category\CollectionFactory $blogCategoryCollectionFactory,
28+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
29+
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory,
30+
\Ves\Brand\Model\ResourceModel\Brand\CollectionFactory $manufacturerCollectionFactory,
31+
Url $url
32+
) {
33+
$this->_blogCategoryCollectionFactory = $blogCategoryCollectionFactory;
34+
$this->_url = $url;
35+
$this->_categoryCollectionFactory = $categoryCollectionFactory;
36+
$this->_categoryFactory = $categoryFactory;
37+
$this->_scopeConfig = $scopeConfig;
38+
$this->_pageCollectionFactory = $pageCollectionFactory;
39+
$this->_postCollectionFactory = $postCollectionFactory;
40+
$this->_productCollectionFactory = $productCollectionFactory;
41+
$this->_manufacturerCollectionFactory = $manufacturerCollectionFactory;
42+
$this->_suffix = $this->_scopeConfig->getValue('catalog/seo/category_url_suffix');
43+
}
44+
45+
public function searchKeyword($keyword)
46+
{
47+
$url_key = str_replace($this->_suffix, '', $keyword);
48+
$url_key = ltrim($url_key, '/');
49+
50+
$result = $this->_categoryCollectionFactory->create()->addAttributeToFilter('url_key', $url_key)->load();
51+
52+
if (count($result->getItems()) > 0) {
53+
$category = $result->getFirstItem();
54+
return [
55+
'type' => 'category',
56+
'id' => $category->getId(),
57+
'url' => $keyword
58+
];
59+
}
60+
61+
$result = $this->_productCollectionFactory->create()->addAttributeToFilter('url_key', $url_key)->load();
62+
63+
if (count($result->getItems()) > 0) {
64+
$product = $result->getFirstItem();
65+
return [
66+
'type' => 'product',
67+
'id' => $product->getId(),
68+
'url' => $keyword
69+
];
70+
}
71+
72+
$result = $this->_pageCollectionFactory->create()
73+
->addFieldToFilter('identifier', ['like' => $url_key])->load();
74+
75+
if (count($result->getItems()) > 0) {
76+
$page = $result->getFirstItem();
77+
return [
78+
'type' => 'page',
79+
'id' => $page->getId(),
80+
'url' => $keyword
81+
];
82+
}
83+
84+
$result = $this->_manufacturerCollectionFactory->create()
85+
->addFieldToFilter('url_key', ['like' => $url_key])->load();
86+
87+
if (count($result->getItems()) > 0) {
88+
$manufacturer = $result->getFirstItem();
89+
return [
90+
'type' => 'manufacturer',
91+
'id' => $manufacturer->getId(),
92+
'url' => $keyword
93+
];
94+
}
95+
96+
$blog_post_url = ltrim($keyword, '/'.$this->_url->getRoute());
97+
$blog_post_url = ltrim($blog_post_url, '/'.$this->_url->getRoute('post'));
98+
$blog_post_url = rtrim($blog_post_url, $this->_url->getUrlSufix('post'));
99+
$blog_post_url = ltrim($blog_post_url, '/');
100+
101+
$result = $this->_postCollectionFactory->create()
102+
->addFieldToFilter('identifier', ['like' => $blog_post_url])->load();
103+
104+
if (count($result->getItems()) > 0) {
105+
$post = $result->getFirstItem();
106+
return [
107+
'type' => 'blog-post',
108+
'id' => $post->getId(),
109+
'url' => $keyword
110+
];
111+
}
112+
113+
$blog_category_url = ltrim($keyword, '/'.$this->_url->getRoute());
114+
$blog_category_url = ltrim($blog_category_url, '/'.$this->_url->getRoute('category'));
115+
$blog_category_url = rtrim($blog_category_url, $this->_url->getUrlSufix('category'));
116+
$blog_category_url = ltrim($blog_category_url, '/');
117+
118+
$result = $this->_blogCategoryCollectionFactory->create()
119+
->addFieldToFilter('identifier', ['like' => $blog_category_url])->load();
120+
121+
if (count($result->getItems()) > 0) {
122+
$blogCategory = $result->getFirstItem();
123+
return [
124+
'type' => 'blog-category',
125+
'id' => $blogCategory->getId(),
126+
'url' => $keyword
127+
];
128+
}
129+
130+
return [
131+
'type' => '',
132+
'id' => 0,
133+
'url' => $keyword
134+
];
135+
}
136+
}

Model/Api/Model/Common/Vuefront.php

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Vuefront\Vuefront\Model\Api\Model\Common;
4+
5+
use \Vuefront\Vuefront\Model\Api\System\Engine\Model;
6+
7+
class Vuefront extends Model
8+
{
9+
private $_appsFactory;
10+
11+
private $_jsonSerializer;
12+
13+
private $_curl;
14+
15+
public function __construct(
16+
\Vuefront\Vuefront\Model\AppsFactory $appsFactory,
17+
\Magento\Framework\HTTP\Client\Curl $curl,
18+
\Magento\Framework\Serialize\Serializer\Json $jsonSerializer
19+
) {
20+
$this->_appsFactory = $appsFactory;
21+
$this->_curl = $curl;
22+
$this->_jsonSerializer = $jsonSerializer;
23+
}
24+
25+
public function editApp($name, $appSetting)
26+
{
27+
$appSetting['codename'] = $name;
28+
29+
30+
$app = $this->_appsFactory->create()->getCollection();
31+
$app->addFieldToSelect('*');
32+
$app->addFieldToFilter('codename', ['like' => $name]);
33+
$result = $app->load();
34+
35+
$model = $result->getFirstItem();
36+
37+
foreach ($appSetting as $key => $value) {
38+
$model->setData($key, $value);
39+
}
40+
41+
$model->save();
42+
}
43+
44+
public function getApp($name)
45+
{
46+
$collection = $this->_appsFactory->create()->getCollection();
47+
48+
foreach ($collection as $key => $value) {
49+
$data = $value->getData();
50+
51+
if ($data['codename'] == $codename) {
52+
return $value->getData();
53+
}
54+
}
55+
56+
return false;
57+
}
58+
59+
public function getAppsForEvent()
60+
{
61+
$collection = $this->_appsFactory->create()->getCollection();
62+
63+
$result = [];
64+
foreach ($collection as $key => $value) {
65+
if (!empty($value['eventUrl'])) {
66+
$result[] = $value;
67+
}
68+
}
69+
70+
return $result;
71+
}
72+
73+
public function pushEvent($name, $data)
74+
{
75+
$apps = $this->getAppsForEvent();
76+
77+
foreach ($apps as $key => $value) {
78+
$output = $this->request($value['eventUrl'], [
79+
'name' => $name,
80+
'data' => $data,
81+
]);
82+
83+
if ($output) {
84+
$data = $output;
85+
}
86+
}
87+
88+
return $data;
89+
}
90+
91+
public function request($url, $data, $token = false)
92+
{
93+
$this->_curl->addHeader('Content-type', 'application/json');
94+
95+
if ($token) {
96+
$this->_curl->addHeader('Authorization', ' Bearer '.$token);
97+
}
98+
99+
$this->_curl->post($url, $this->_jsonSerializer->serialize($data));
100+
101+
$result = $this->_curl->getBody();
102+
103+
$result = $this->_jsonSerializer->unserialize($result);
104+
105+
return $result;
106+
}
107+
}

0 commit comments

Comments
 (0)