-
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.
feat: update for new version vuefront
- Loading branch information
1 parent
112719b
commit 234ef9f
Showing
60 changed files
with
6,662 additions
and
4,831 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace Vuefront\Vuefront\Model\Api\Model\Common; | ||
|
||
use \Vuefront\Vuefront\Model\Api\System\Engine\Model; | ||
|
||
class Customer extends Model | ||
{ | ||
private $_collectionFactory; | ||
private $_customerFactory; | ||
|
||
public function __construct( | ||
\Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $collectionFactory, | ||
\Magento\Customer\Model\Customer $customerFactory | ||
) { | ||
$this->_collectionFactory = $collectionFactory; | ||
$this->_customerFactory = $customerFactory; | ||
} | ||
|
||
public function getCustomer($customer_id) | ||
{ | ||
return $this->_customerFactory->create()->load($customer_id); | ||
} | ||
|
||
public function getCustomers($data) | ||
{ | ||
/** @var $collection \Magento\Customer\Model\ResourceModel\Customer\Collection */ | ||
$collection = $this->_collectionFactory->create(); | ||
|
||
if (!empty($data['search'])) { | ||
$collection->addFieldToFilter([ | ||
['attribute'=>'firstname', 'like' => '%' . $data['search'] . '%'], | ||
['attribute'=>'lastname', 'like' => '%' . $data['search'] . '%'], | ||
]); | ||
} | ||
|
||
if ($data['size'] != '-1') { | ||
$collection->setPageSize($data['size']); | ||
$collection->setCurPage($data['page']); | ||
} | ||
|
||
if (isset($data['order']) && ($data['order'] == 'DESC')) { | ||
$order = "DESC"; | ||
} else { | ||
$order = "ASC"; | ||
} | ||
|
||
$sort_data = [ | ||
'id' => 'entity_id', | ||
'sort_order' => 'position' | ||
]; | ||
|
||
if (isset($data['sort']) && in_array($data['sort'], array_keys($sort_data))) { | ||
$sort = $sort_data[$data['sort']]; | ||
} else { | ||
$sort = "entity_id"; | ||
} | ||
|
||
$collection->setOrder($sort, $order); | ||
$collection->load(); | ||
|
||
return $collection; | ||
} | ||
} |
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,136 @@ | ||
<?php | ||
|
||
namespace Vuefront\Vuefront\Model\Api\Model\Common; | ||
|
||
use \Vuefront\Vuefront\Model\Api\System\Engine\Model; | ||
use Magefan\Blog\Model\Url; | ||
|
||
|
||
class Seo extends Model | ||
{ | ||
private $_categoryFactory; | ||
private $_categoryCollectionFactory; | ||
private $_blogCategoryCollectionFactory; | ||
private $_pageCollectionFactory; | ||
private $_postCollectionFactory; | ||
private $_productCollectionFactory; | ||
private $_manufacturerCollectionFactory; | ||
private $_scopeConfig; | ||
private $_suffix; | ||
private $_url; | ||
|
||
public function __construct( | ||
\Magento\Catalog\Model\CategoryFactory $categoryFactory, | ||
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory, | ||
\Magento\Cms\Model\ResourceModel\Page\CollectionFactory $pageCollectionFactory, | ||
\Magefan\Blog\Model\ResourceModel\Post\CollectionFactory $postCollectionFactory, | ||
\Magefan\Blog\Model\ResourceModel\Category\CollectionFactory $blogCategoryCollectionFactory, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory, | ||
\Ves\Brand\Model\ResourceModel\Brand\CollectionFactory $manufacturerCollectionFactory, | ||
Url $url | ||
) { | ||
$this->_blogCategoryCollectionFactory = $blogCategoryCollectionFactory; | ||
$this->_url = $url; | ||
$this->_categoryCollectionFactory = $categoryCollectionFactory; | ||
$this->_categoryFactory = $categoryFactory; | ||
$this->_scopeConfig = $scopeConfig; | ||
$this->_pageCollectionFactory = $pageCollectionFactory; | ||
$this->_postCollectionFactory = $postCollectionFactory; | ||
$this->_productCollectionFactory = $productCollectionFactory; | ||
$this->_manufacturerCollectionFactory = $manufacturerCollectionFactory; | ||
$this->_suffix = $this->_scopeConfig->getValue('catalog/seo/category_url_suffix'); | ||
} | ||
|
||
public function searchKeyword($keyword) | ||
{ | ||
$url_key = str_replace($this->_suffix, '', $keyword); | ||
$url_key = ltrim($url_key, '/'); | ||
|
||
$result = $this->_categoryCollectionFactory->create()->addAttributeToFilter('url_key', $url_key)->load(); | ||
|
||
if (count($result->getItems()) > 0) { | ||
$category = $result->getFirstItem(); | ||
return [ | ||
'type' => 'category', | ||
'id' => $category->getId(), | ||
'url' => $keyword | ||
]; | ||
} | ||
|
||
$result = $this->_productCollectionFactory->create()->addAttributeToFilter('url_key', $url_key)->load(); | ||
|
||
if (count($result->getItems()) > 0) { | ||
$product = $result->getFirstItem(); | ||
return [ | ||
'type' => 'product', | ||
'id' => $product->getId(), | ||
'url' => $keyword | ||
]; | ||
} | ||
|
||
$result = $this->_pageCollectionFactory->create() | ||
->addFieldToFilter('identifier', ['like' => $url_key])->load(); | ||
|
||
if (count($result->getItems()) > 0) { | ||
$page = $result->getFirstItem(); | ||
return [ | ||
'type' => 'page', | ||
'id' => $page->getId(), | ||
'url' => $keyword | ||
]; | ||
} | ||
|
||
$result = $this->_manufacturerCollectionFactory->create() | ||
->addFieldToFilter('url_key', ['like' => $url_key])->load(); | ||
|
||
if (count($result->getItems()) > 0) { | ||
$manufacturer = $result->getFirstItem(); | ||
return [ | ||
'type' => 'manufacturer', | ||
'id' => $manufacturer->getId(), | ||
'url' => $keyword | ||
]; | ||
} | ||
|
||
$blog_post_url = ltrim($keyword, '/'.$this->_url->getRoute()); | ||
$blog_post_url = ltrim($blog_post_url, '/'.$this->_url->getRoute('post')); | ||
$blog_post_url = rtrim($blog_post_url, $this->_url->getUrlSufix('post')); | ||
$blog_post_url = ltrim($blog_post_url, '/'); | ||
|
||
$result = $this->_postCollectionFactory->create() | ||
->addFieldToFilter('identifier', ['like' => $blog_post_url])->load(); | ||
|
||
if (count($result->getItems()) > 0) { | ||
$post = $result->getFirstItem(); | ||
return [ | ||
'type' => 'blog-post', | ||
'id' => $post->getId(), | ||
'url' => $keyword | ||
]; | ||
} | ||
|
||
$blog_category_url = ltrim($keyword, '/'.$this->_url->getRoute()); | ||
$blog_category_url = ltrim($blog_category_url, '/'.$this->_url->getRoute('category')); | ||
$blog_category_url = rtrim($blog_category_url, $this->_url->getUrlSufix('category')); | ||
$blog_category_url = ltrim($blog_category_url, '/'); | ||
|
||
$result = $this->_blogCategoryCollectionFactory->create() | ||
->addFieldToFilter('identifier', ['like' => $blog_category_url])->load(); | ||
|
||
if (count($result->getItems()) > 0) { | ||
$blogCategory = $result->getFirstItem(); | ||
return [ | ||
'type' => 'blog-category', | ||
'id' => $blogCategory->getId(), | ||
'url' => $keyword | ||
]; | ||
} | ||
|
||
return [ | ||
'type' => '', | ||
'id' => 0, | ||
'url' => $keyword | ||
]; | ||
} | ||
} |
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,107 @@ | ||
<?php | ||
|
||
namespace Vuefront\Vuefront\Model\Api\Model\Common; | ||
|
||
use \Vuefront\Vuefront\Model\Api\System\Engine\Model; | ||
|
||
class Vuefront extends Model | ||
{ | ||
private $_appsFactory; | ||
|
||
private $_jsonSerializer; | ||
|
||
private $_curl; | ||
|
||
public function __construct( | ||
\Vuefront\Vuefront\Model\AppsFactory $appsFactory, | ||
\Magento\Framework\HTTP\Client\Curl $curl, | ||
\Magento\Framework\Serialize\Serializer\Json $jsonSerializer | ||
) { | ||
$this->_appsFactory = $appsFactory; | ||
$this->_curl = $curl; | ||
$this->_jsonSerializer = $jsonSerializer; | ||
} | ||
|
||
public function editApp($name, $appSetting) | ||
{ | ||
$appSetting['codename'] = $name; | ||
|
||
|
||
$app = $this->_appsFactory->create()->getCollection(); | ||
$app->addFieldToSelect('*'); | ||
$app->addFieldToFilter('codename', ['like' => $name]); | ||
$result = $app->load(); | ||
|
||
$model = $result->getFirstItem(); | ||
|
||
foreach ($appSetting as $key => $value) { | ||
$model->setData($key, $value); | ||
} | ||
|
||
$model->save(); | ||
} | ||
|
||
public function getApp($name) | ||
{ | ||
$collection = $this->_appsFactory->create()->getCollection(); | ||
|
||
foreach ($collection as $key => $value) { | ||
$data = $value->getData(); | ||
|
||
if ($data['codename'] == $codename) { | ||
return $value->getData(); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function getAppsForEvent() | ||
{ | ||
$collection = $this->_appsFactory->create()->getCollection(); | ||
|
||
$result = []; | ||
foreach ($collection as $key => $value) { | ||
if (!empty($value['eventUrl'])) { | ||
$result[] = $value; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
public function pushEvent($name, $data) | ||
{ | ||
$apps = $this->getAppsForEvent(); | ||
|
||
foreach ($apps as $key => $value) { | ||
$output = $this->request($value['eventUrl'], [ | ||
'name' => $name, | ||
'data' => $data, | ||
]); | ||
|
||
if ($output) { | ||
$data = $output; | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
public function request($url, $data, $token = false) | ||
{ | ||
$this->_curl->addHeader('Content-type', 'application/json'); | ||
|
||
if ($token) { | ||
$this->_curl->addHeader('Authorization', ' Bearer '.$token); | ||
} | ||
|
||
$this->_curl->post($url, $this->_jsonSerializer->serialize($data)); | ||
|
||
$result = $this->_curl->getBody(); | ||
|
||
$result = $this->_jsonSerializer->unserialize($result); | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.