本文整理汇总了PHP中Magento\Framework\Model\AbstractModel::getStoreIds方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractModel::getStoreIds方法的具体用法?PHP AbstractModel::getStoreIds怎么用?PHP AbstractModel::getStoreIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\AbstractModel
的用法示例。
在下文中一共展示了AbstractModel::getStoreIds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundSave
/**
* @param \Magento\Store\Model\ResourceModel\Group $object
* @param callable $proceed
* @param AbstractModel $group
* @return \Magento\Store\Model\ResourceModel\Group
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundSave(\Magento\Store\Model\ResourceModel\Group $object, \Closure $proceed, AbstractModel $group)
{
$originGroup = $group;
$result = $proceed($originGroup);
if (!$group->isObjectNew() && ($group->dataHasChangedFor('website_id') || $group->dataHasChangedFor('root_category_id'))) {
$this->storeManager->reinitStores();
foreach ($group->getStoreIds() as $storeId) {
$this->urlPersist->deleteByData([UrlRewrite::STORE_ID => $storeId]);
}
$this->urlPersist->replace($this->generateCategoryUrls($group->getRootCategoryId(), $group->getStoreIds()));
$this->urlPersist->replace($this->generateProductUrls($group->getWebsiteId(), $group->getOrigData('website_id')));
}
return $result;
}
示例2: saveStoreRelation
/**
* Saves relation between thesaurus and store
*
* @param \Magento\Framework\Model\AbstractModel $object Thesaurus to save
*
* @return void
*/
private function saveStoreRelation(\Magento\Framework\Model\AbstractModel $object)
{
$storeIds = $object->getStoreIds();
if (is_array($storeIds) && count($storeIds) > 0) {
if (in_array(0, $storeIds)) {
$storeIds = [0];
}
$storeLinks = [];
$deleteCondition = [ThesaurusInterface::THESAURUS_ID . " = ?" => $object->getThesaurusId()];
foreach ($storeIds as $key => $storeId) {
$storeLinks[] = [ThesaurusInterface::THESAURUS_ID => (int) $object->getThesaurusId(), ThesaurusInterface::STORE_ID => (int) $storeId];
$storeIds[$key] = (int) $storeId;
}
$deleteCondition[ThesaurusInterface::STORE_ID . " NOT IN (?)"] = array_keys($storeIds);
$this->getConnection()->delete($this->getTable(ThesaurusInterface::STORE_TABLE_NAME), $deleteCondition);
$this->getConnection()->insertOnDuplicate($this->getTable(ThesaurusInterface::STORE_TABLE_NAME), $storeLinks, array_keys(current($storeLinks)));
}
}
示例3: _afterSave
/**
* Assign post to store views, categories, related posts, etc.
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$oldIds = $this->lookupStoreIds($object->getId());
$newIds = (array) $object->getStoreIds();
if (!$newIds) {
$newIds = [0];
}
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_store', 'store_id');
/* Save category & tag links */
foreach (['category' => 'categories', 'tag' => 'tags'] as $linkType => $dataKey) {
$newIds = (array) $object->getData($dataKey);
foreach ($newIds as $key => $id) {
if (!$id) {
// e.g.: zero
unset($newIds[$key]);
}
}
if (is_array($newIds)) {
$lookup = 'lookup' . ucfirst($linkType) . 'Ids';
$oldIds = $this->{$lookup}($object->getId());
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_' . $linkType, $linkType . '_id');
}
}
/* Save tags links */
$newIds = (array) $object->getTags();
foreach ($newIds as $key => $id) {
if (!$id) {
// e.g.: zero
unset($newIds[$key]);
}
}
if (is_array($newIds)) {
$oldIds = $this->lookupTagIds($object->getId());
$this->_updateLinks($object, $newIds, $oldIds, 'magefan_blog_post_tag', 'tag_id');
}
/* Save related post & product links */
if ($links = $object->getData('links')) {
if (is_array($links)) {
foreach (['post', 'product'] as $linkType) {
if (!empty($links[$linkType]) && is_array($links[$linkType])) {
$linksData = $links[$linkType];
$lookup = 'lookupRelated' . ucfirst($linkType) . 'Ids';
$oldIds = $this->{$lookup}($object->getId());
$this->_updateLinks($object, array_keys($linksData), $oldIds, 'magefan_blog_post_related' . $linkType, 'related_id', $linksData);
}
}
}
}
return parent::_afterSave($object);
}
示例4: _afterSave
/**
* Assign category to store views
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$oldStoreIds = $this->lookupStoreIds($object->getId());
$newStoreIds = (array) $object->getStoreIds();
if (!$newStoreIds) {
$newStoreIds = [0];
}
$table = $this->getTable('magefan_blog_category_store');
$insert = array_diff($newStoreIds, $oldStoreIds);
$delete = array_diff($oldStoreIds, $newStoreIds);
if ($delete) {
$where = ['category_id = ?' => (int) $object->getId(), 'store_id IN (?)' => $delete];
$this->getConnection()->delete($table, $where);
}
if ($insert) {
$data = [];
foreach ($insert as $storeId) {
$data[] = ['category_id' => (int) $object->getId(), 'store_id' => (int) $storeId];
}
$this->getConnection()->insertMultiple($table, $data);
}
return parent::_afterSave($object);
}