/**
  * Apply coupon before one page checkout.
  *
  * @return void
  */
 public function run()
 {
     if ($this->salesRule !== null) {
         $this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($this->salesRule->getCouponCode());
         $this->checkoutCart->getTotalsBlock()->waitForUpdatedTotals();
     }
 }
 /**
  * Enter discount code and click apply button.
  *
  * @param SalesRule $code
  * @return void
  */
 public function applyCouponCode(SalesRule $code)
 {
     $couponField = $this->_rootElement->find($this->couponCode);
     $couponField->click();
     $couponField->keys(str_split($code->getCouponCode()));
     $this->waitForElementVisible($this->applyButton, Locator::SELECTOR_XPATH);
     $this->_rootElement->find($this->applyButton, Locator::SELECTOR_XPATH)->click();
     $this->getTemplateBlock()->waitLoader();
 }
Exemple #3
0
 /**
  * Create coupon related to sales rule .
  *
  * @param int $ruleId
  * @return void
  * @throws \Exception
  */
 protected function createCoupon($ruleId)
 {
     if (!$this->fixture->hasData('coupon_code')) {
         return;
     }
     $url = $_ENV['app_frontend_url'] . 'rest/V1/coupons';
     $data = ['coupon' => array_filter(['rule_id' => $ruleId, 'code' => $this->fixture->getCouponCode(), 'type' => $this->data['coupon_type'], 'usage_limit' => isset($this->data['uses_per_coupon']) ? $this->data['uses_per_coupon'] : null, 'usage_per_customer' => isset($this->data['usage_per_customer']) ? $this->data['usage_per_customer'] : null, 'is_primary' => true])];
     $this->webapiTransport->write($url, $data);
     $response = json_decode($this->webapiTransport->read(), true);
     $this->webapiTransport->close();
     if (empty($response['coupon_id'])) {
         $this->eventManager->dispatchEvent(['webapi_failed'], [$response]);
         throw new \Exception('Coupon creation by webapi handler was not successful!');
     }
 }
 /**
  * Apply coupon before one page checkout.
  *
  * @return void
  */
 public function run()
 {
     if ($this->salesRule !== null) {
         $this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($this->salesRule->getCouponCode());
     }
 }
Exemple #5
0
 /**
  * Prepare coupon data.
  *
  * @param SalesRule $data
  * @return array
  */
 protected function prepareCouponCode(SalesRule $data)
 {
     return ['order' => ['coupon' => ['code' => $data->getCouponCode()]]];
 }
Exemple #6
0
 /**
  * Enter discount code and click apply button.
  *
  * @param SalesRule $code
  * @return void
  */
 public function applyCouponCode(SalesRule $code)
 {
     $this->_rootElement->find($this->couponCode)->setValue($code->getCouponCode());
     $this->_rootElement->find($this->applyButton, Locator::SELECTOR_XPATH)->click();
 }
 /**
  * 1. Navigate to frontend
  * 2. If "Log Out" link is visible and "isLoggedIn" empty
  *    - makes logout
  * 3. If "isLoggedIn" not empty
  *    - login as customer
  * 4. Clear shopping cart
  * 5. Add test product(s) to shopping cart with specify quantity
  * 6. If "salesRule/data/coupon_code" not empty:
  *    - fill "Enter your code" input in Dіscount Codes
  *    - click "Apply Coupon" button
  * 7. If "address/data/country_id" not empty:
  *    On Estimate Shipping and Tax:
  *    - fill Country, State/Province, Zip/Postal Code
  *    - click 'Get a Quote' button
  *    - select 'Flat Rate' shipping
  *    - click 'Update Total' button
  * 8. Implementation assert
  *
  * @param CheckoutCart $checkoutCart
  * @param CmsIndex $cmsIndex
  * @param CustomerAccountLogin $customerAccountLogin
  * @param CustomerAccountLogout $customerAccountLogout
  * @param CatalogCategoryView $catalogCategoryView
  * @param CatalogProductView $catalogProductView
  * @param SalesRule $salesRule
  * @param SalesRule $salesRuleOrigin
  * @param array $productQuantity
  * @param CatalogProductSimple $productForSalesRule1
  * @param CatalogProductSimple $productForSalesRule2
  * @param Customer $customer
  * @param Address $address
  * @param int|null $isLoggedIn
  * @param array $shipping
  * @param array $cartPrice
  * @return void
  *
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function processAssert(CheckoutCart $checkoutCart, CmsIndex $cmsIndex, CustomerAccountLogin $customerAccountLogin, CustomerAccountLogout $customerAccountLogout, CatalogCategoryView $catalogCategoryView, CatalogProductView $catalogProductView, SalesRule $salesRule, SalesRule $salesRuleOrigin, array $productQuantity, CatalogProductSimple $productForSalesRule1, CatalogProductSimple $productForSalesRule2 = null, Customer $customer = null, Address $address = null, $isLoggedIn = null, array $shipping = [], array $cartPrice = [])
 {
     $this->checkoutCart = $checkoutCart;
     $this->cmsIndex = $cmsIndex;
     $this->customerAccountLogin = $customerAccountLogin;
     $this->customerAccountLogout = $customerAccountLogout;
     $this->catalogCategoryView = $catalogCategoryView;
     $this->catalogProductView = $catalogProductView;
     $this->productForSalesRule1 = $productForSalesRule1;
     $this->productForSalesRule2 = $productForSalesRule2;
     $this->cartPrice = $cartPrice;
     if ($customer !== null) {
         $this->customer = $customer;
     }
     $isLoggedIn ? $this->login() : $this->customerAccountLogout->open();
     $this->checkoutCart->open()->getCartBlock()->clearShoppingCart();
     $this->addProductsToCart($productQuantity);
     $this->checkoutCart->open();
     if ($address !== null) {
         $this->checkoutCart->getShippingBlock()->fillEstimateShippingAndTax($address);
         $this->checkoutCart->getShippingBlock()->selectShippingMethod($shipping);
     }
     if ($salesRule->getCouponCode() || $salesRuleOrigin->getCouponCode()) {
         $this->checkoutCart->getDiscountCodesBlock()->applyCouponCode($salesRule->getCouponCode() ? $salesRule->getCouponCode() : $salesRuleOrigin->getCouponCode());
     }
     $this->assert();
 }