本文整理汇总了PHP中Magento\Framework\DataObject::setStoreId方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObject::setStoreId方法的具体用法?PHP DataObject::setStoreId怎么用?PHP DataObject::setStoreId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\DataObject
的用法示例。
在下文中一共展示了DataObject::setStoreId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
/**
* Before save
*
* @param \Magento\Framework\DataObject $object
* @return $this
*/
public function beforeSave($object)
{
if ($object->getId()) {
return $this;
}
if (!$object->hasStoreId()) {
$object->setStoreId($this->_storeManager->getStore()->getId());
}
if (!$object->hasData('created_in')) {
$object->setData('created_in', $this->_storeManager->getStore($object->getStoreId())->getName());
}
return $this;
}
示例2: _beforeSave
/**
* Check customer scope, email and confirmation key before saving
*
* @param \Magento\Framework\DataObject $customer
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
protected function _beforeSave(\Magento\Framework\DataObject $customer)
{
/** @var \Magento\Customer\Model\Customer $customer */
if ($customer->getStoreId() === null) {
$customer->setStoreId($this->storeManager->getStore()->getId());
}
$customer->getGroupId();
parent::_beforeSave($customer);
if (!$customer->getEmail()) {
throw new ValidatorException(__('Please enter a customer email.'));
}
$connection = $this->getConnection();
$bind = ['email' => $customer->getEmail()];
$select = $connection->select()->from($this->getEntityTable(), [$this->getEntityIdField()])->where('email = :email');
if ($customer->getSharingConfig()->isWebsiteScope()) {
$bind['website_id'] = (int) $customer->getWebsiteId();
$select->where('website_id = :website_id');
}
if ($customer->getId()) {
$bind['entity_id'] = (int) $customer->getId();
$select->where('entity_id != :entity_id');
}
$result = $connection->fetchOne($select, $bind);
if ($result) {
throw new AlreadyExistsException(__('A customer with the same email already exists in an associated website.'));
}
// set confirmation key logic
if ($customer->getForceConfirmed() || $customer->getPasswordHash() == '') {
$customer->setConfirmation(null);
} elseif (!$customer->getId() && $customer->isConfirmationRequired()) {
$customer->setConfirmation($customer->getRandomConfirmationKey());
}
// remove customer confirmation key from database, if empty
if (!$customer->getConfirmation()) {
$customer->setConfirmation(null);
}
$this->_validate($customer);
return $this;
}
示例3: _getAllProductImages
/**
* Get all product images
*
* @param \Magento\Framework\DataObject $product
* @param int $storeId
* @return array
*/
protected function _getAllProductImages($product, $storeId)
{
$product->setStoreId($storeId);
$gallery = $this->_mediaAttribute->loadProductGalleryByAttributeId($product, $this->_getMediaGalleryModel()->getAttribute()->getId());
$imagesCollection = [];
if ($gallery) {
$productMediaPath = $this->_getMediaConfig()->getBaseMediaUrlAddition();
foreach ($gallery as $image) {
$imagesCollection[] = new \Magento\Framework\DataObject(['url' => $productMediaPath . $image['file'], 'caption' => $image['label'] ? $image['label'] : $image['label_default']]);
}
}
return $imagesCollection;
}