Ejemplo n.º 1
0
 public function testGetStoreObjectStoreParameter()
 {
     $storeMock = $this->getMockBuilder('Magento\\Store\\Api\\Data\\StoreInterface')->disableOriginalConstructor()->setMethods([])->getMock();
     $actualStore = $this->model->getStore($storeMock);
     $this->assertInstanceOf('Magento\\Store\\Api\\Data\\StoreInterface', $actualStore);
     $this->assertEquals($storeMock, $actualStore);
 }
Ejemplo n.º 2
0
 /**
  * Returns catalog rule value
  *
  * @return float|boolean
  */
 public function getValue()
 {
     if (null === $this->value) {
         $this->value = $this->resourceRuleFactory->create()->getRulePrice($this->dateTime->scopeTimeStamp($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId());
         $this->value = $this->value ? floatval($this->value) : false;
     }
     return $this->value;
 }
Ejemplo n.º 3
0
 /**
  * Returns catalog rule value
  *
  * @return float|boolean
  */
 public function getValue()
 {
     if (null === $this->value) {
         if ($this->product->hasData(self::PRICE_CODE)) {
             $this->value = floatval($this->product->getData(self::PRICE_CODE)) ?: false;
         } else {
             $this->value = $this->getRuleResource()->getRulePrice($this->dateTime->scopeDate($this->storeManager->getStore()->getId()), $this->storeManager->getStore()->getWebsiteId(), $this->customerSession->getCustomerGroupId(), $this->product->getId());
             $this->value = $this->value ? floatval($this->value) : false;
             if ($this->value) {
                 $this->value = $this->priceCurrency->convertAndRound($this->value);
             }
         }
     }
     return $this->value;
 }
Ejemplo n.º 4
0
 public function __construct(Context $context, array $data = [], StoreManager $sManager, Webtracking $webtracking, Session $session)
 {
     parent::__construct($context, $data);
     $this->_activeStore = $sManager->getStore();
     $this->_webtracking = $webtracking;
     $this->_session = $session;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option)
 {
     $option->setStoreId($this->storeManager->getStore()->getId());
     $option->setParentId($product->getId());
     $optionId = $option->getOptionId();
     $linksToAdd = [];
     if (!$optionId) {
         $option->setDefaultTitle($option->getTitle());
         if (is_array($option->getProductLinks())) {
             $linksToAdd = $option->getProductLinks();
         }
     } else {
         $optionCollection = $this->type->getOptionsCollection($product);
         /** @var \Magento\Bundle\Model\Option $existingOption */
         $existingOption = $optionCollection->getItemById($option->getOptionId());
         if (!isset($existingOption) || !$existingOption->getOptionId()) {
             throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
         }
         $option->setData(array_merge($existingOption->getData(), $option->getData()));
         $this->updateOptionSelection($product, $option);
     }
     try {
         $this->optionResource->save($option);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save option'), $e);
     }
     /** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
     foreach ($linksToAdd as $linkedProduct) {
         $this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct);
     }
     return $option->getOptionId();
 }
 public function __construct(Session $customerSession, CheckoutSession $CheckoutSession, Registry $registry, Subscriber $subscriber, Group $customerGroupModel, Queue $remarketyQueue, Store $store, ScopeConfigInterface $scopeConfig, StoreManager $sManager)
 {
     parent::__construct($registry, $subscriber, $customerGroupModel, $remarketyQueue, $store, $scopeConfig);
     $this->session = $customerSession;
     $this->_checkoutSession = $CheckoutSession;
     $this->_store = $sManager->getStore();
 }
 /**
  * Execute method.
  */
 public function execute()
 {
     $code = $this->getRequest()->getParam('code', false);
     $userId = $this->getRequest()->getParam('state');
     //load admin user
     $adminUser = $this->adminUser->create()->load($userId);
     //app code and admin user must be present
     if ($code && $adminUser->getId()) {
         $clientId = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_ID);
         $clientSecret = $this->scopeConfig->getValue(\Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_CLIENT_SECRET_ID);
         //callback uri if not set custom
         $redirectUri = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true);
         $redirectUri .= 'connector/email/callback';
         $data = 'client_id=' . $clientId . '&client_secret=' . $clientSecret . '&redirect_uri=' . $redirectUri . '&grant_type=authorization_code' . '&code=' . $code;
         //callback url
         $url = $this->config->getTokenUrl();
         //@codingStandardsIgnoreStart
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_TIMEOUT, 10);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
         curl_setopt($ch, CURLOPT_POST, count($data));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
         curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/x-www-form-urlencoded']);
         $response = json_decode(curl_exec($ch));
         if ($response === false) {
             $this->helper->error('Error Number: ' . curl_errno($ch), []);
         }
         if (isset($response->error)) {
             $this->helper->error('OAUTH failed ' . $response->error, []);
         } elseif (isset($response->refresh_token)) {
             //save the refresh token to the admin user
             $adminUser->setRefreshToken($response->refresh_token)->save();
         }
         //@codingStandardsIgnoreEnd
     }
     //redirect to automation index page
     $this->_redirect($this->adminHelper->getUrl('dotdigitalgroup_email/studio'));
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function update($productSku, $optionId, \Magento\Bundle\Service\V1\Data\Product\Option $option)
 {
     $product = $this->getProduct($productSku);
     $optionCollection = $this->type->getOptionsCollection($product);
     $optionCollection->setIdFilter($optionId);
     /** @var \Magento\Bundle\Model\Option $optionModel */
     $optionModel = $optionCollection->getFirstItem();
     $updateOption = $this->optionConverter->getModelFromData($option, $optionModel);
     if (!$updateOption->getId()) {
         throw new NoSuchEntityException('Requested option doesn\'t exist');
     }
     $updateOption->setStoreId($this->storeManager->getStore()->getId());
     /**
      * @var Link[] $existingProductLinks
      */
     $existingProductLinks = $optionModel->getProductLinks();
     if (!is_array($existingProductLinks)) {
         $existingProductLinks = array();
     }
     /**
      * @var Link[] $newProductLinks
      */
     $newProductLinks = $option->getProductLinks();
     if (is_null($newProductLinks)) {
         $newProductLinks = array();
     }
     /**
      * @var Link[] $linksToDelete
      */
     $linksToDelete = array_udiff($existingProductLinks, $newProductLinks, array($this, 'compareLinks'));
     foreach ($linksToDelete as $link) {
         $this->linkWriteService->removeChild($productSku, $option->getId(), $link->getSku());
     }
     /**
      * @var Link[] $linksToAdd
      */
     $linksToAdd = array_udiff($newProductLinks, $existingProductLinks, array($this, 'compareLinks'));
     foreach ($linksToAdd as $link) {
         $this->linkWriteService->addChild($productSku, $option->getId(), $link);
     }
     try {
         $updateOption->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save option', [], $e);
     }
     return true;
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function update($productSku, $optionId, \Magento\Bundle\Service\V1\Data\Product\Option $option)
 {
     $product = $this->getProduct($productSku);
     $optionCollection = $this->type->getOptionsCollection($product);
     $optionCollection->setIdFilter($optionId);
     /** @var \Magento\Bundle\Model\Option $optionModel */
     $optionModel = $optionCollection->getFirstItem();
     $updateOption = $this->optionConverter->getModelFromData($option, $optionModel);
     if (!$updateOption->getId()) {
         throw new NoSuchEntityException('Requested option doesn\'t exist');
     }
     $updateOption->setStoreId($this->storeManager->getStore()->getId());
     try {
         $updateOption->save();
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not save option', [], $e);
     }
     return true;
 }
Ejemplo n.º 10
0
 /**
  * @param $store
  * @param $email
  * @return array
  */
 protected function _createNewCoupon($store, $email)
 {
     $collection = $this->_objectManager->create('Magento\\SalesRule\\Model\\Rule')->getCollection()->addFieldToFilter('name', ['like' => 'Abandoned coupon ' . $email]);
     if (!count($collection)) {
         $websiteid = $this->_storeManager->getStore()->getWebsiteId();
         $fromDate = date("Y-m-d");
         $toDate = date('Y-m-d', strtotime($fromDate . " + {$this->couponexpiredays} day"));
         if ($this->coupontype == 1) {
             $action = 'cart_fixed';
             $discount = $this->_storeManager->getStore()->getCurrentCurrencyCode() . "{$this->couponamount}";
         } elseif ($this->coupontype == 2) {
             $action = 'by_percent';
             $discount = "{$this->couponamount}%";
         }
         // $customer_group = new Mage_Customer_Model_Group();
         $customer_group = $this->_objectManager->create('Magento\\Customer\\Model\\Group');
         $allGroups = $customer_group->getCollection()->toOptionHash();
         $groups = array();
         foreach ($allGroups as $groupid => $name) {
             $groups[] = $groupid;
         }
         // $coupon_rule = Mage::getModel('salesrule/rule');
         $coupon_rule = $this->_objectManager->create('Magento\\SalesRule\\Model\\Rule');
         $coupon_rule->setName("Abandoned coupon {$email}")->setDescription("Abandoned coupon {$email}")->setStopRulesProcessing(0)->setFromDate($fromDate)->setToDate($toDate)->setIsActive(1)->setCouponType(2)->setUsesPerCoupon(1)->setUsesPerCustomer(1)->setCustomerGroupIds($groups)->setProductIds('')->setLengthMin($this->couponlength)->setLengthMax($this->couponlength)->setSortOrder(0)->setStoreLabels(array($this->couponlabel))->setSimpleAction($action)->setDiscountAmount($this->couponamount)->setDiscountQty(0)->setDiscountStep('0')->setSimpleFreeShipping('0')->setApplyToShipping('0')->setIsRss(0)->setWebsiteIds($websiteid);
         // $uniqueId = Mage::getSingleton('salesrule/coupon_codegenerator', array('length' => $this->couponlength))->generateCode();
         $uniqueId = $this->_objectManager->create('Magento\\SalesRule\\Model\\Group\\Codegenerator')->setLengthMin($this->couponlength)->setLengthMax($this->couponlength)->generateCode();
         $coupon_rule->setCouponCode($uniqueId);
         $coupon_rule->save();
         return array($uniqueId, $discount, $toDate);
     } else {
         $coupon = $collection->getFirstItem();
         if ($coupon->getSimpleAction() == 'cart_fixed') {
             $discount = $this->_storeManager->getStore()->getCurrentCurrencyCode() . ($coupon->getDiscountAmount() + 0);
         } else {
             $discount = $coupon->getDiscountAmount() + 0;
         }
         return array($coupon->getCode(), $discount, $coupon->getToDate());
     }
 }
Ejemplo n.º 11
0
 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, \Magento\Bundle\Api\Data\OptionInterface $option)
 {
     $option->setStoreId($this->storeManager->getStore()->getId());
     $option->setParentId($product->getId());
     if (!$option->getOptionId()) {
         $option->setDefaultTitle($option->getTitle());
         $linksToAdd = is_array($option->getProductLinks()) ? $option->getProductLinks() : [];
     } else {
         $optionCollection = $this->type->getOptionsCollection($product);
         $optionCollection->setIdFilter($option->getOptionId());
         /** @var \Magento\Bundle\Model\Option $existingOption */
         $existingOption = $optionCollection->getFirstItem();
         if (!$existingOption->getOptionId()) {
             throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
         }
         $option->setData(array_merge($existingOption->getData(), $option->getData()));
         /** @var \Magento\Bundle\Api\Data\LinkInterface[] $existingLinks */
         $existingLinks = is_array($existingOption->getProductLinks()) ? $existingOption->getProductLinks() : [];
         /** @var \Magento\Bundle\Api\Data\LinkInterface[] $newProductLinks */
         $newProductLinks = is_array($option->getProductLinks()) ? $option->getProductLinks() : [];
         /** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToDelete */
         $linksToDelete = array_udiff($existingLinks, $newProductLinks, [$this, 'compareLinks']);
         foreach ($linksToDelete as $link) {
             $this->linkManagement->removeChild($product->getSku(), $option->getOptionId(), $link->getSku());
         }
         /** @var \Magento\Bundle\Api\Data\LinkInterface[] $linksToAdd */
         $linksToAdd = array_udiff($newProductLinks, $existingLinks, [$this, 'compareLinks']);
     }
     try {
         $this->optionResource->save($option);
     } catch (\Exception $e) {
         throw new CouldNotSaveException(__('Could not save option'), $e);
     }
     /** @var \Magento\Bundle\Api\Data\LinkInterface $linkedProduct */
     foreach ($linksToAdd as $linkedProduct) {
         $this->linkManagement->addChild($product, $option->getOptionId(), $linkedProduct);
     }
     return $option->getOptionId();
 }
Ejemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function getStore($storeId = null)
 {
     $result = $this->decoratedStoreManager->getStore($storeId);
     $this->dispatchInitCurrentStoreAfterEvent();
     return $result;
 }
 /**
  * Load collection with filters applied
  *
  * @param string $entityType
  * @param string $formCode
  * @return \Magento\Customer\Model\ResourceModel\Form\Attribute\Collection
  */
 public function loadAttributesCollection($entityType, $formCode)
 {
     $attributesFormCollection = $this->attrFormCollectionFactory->create();
     $attributesFormCollection->setStore($this->storeManager->getStore())->setEntityType($entityType)->addFormCodeFilter($formCode)->setSortOrder();
     return $attributesFormCollection;
 }
Ejemplo n.º 14
0
 public function __construct(Config $resourceConfig, StoreManager $sManager, ScopeConfigInterface $scopeConfig)
 {
     $this->_configResource = $resourceConfig;
     $this->_activeStore = $sManager->getStore();
     $this->_configRead = $scopeConfig;
 }