Example #1
0
 public function ajaxMigrationOptions()
 {
     try {
         //			1 - if first time ajax request
         if ($_POST['msgLog'] == 1) {
             Migration::saveLog(__('Migration options START.', 'jigoshop'), true);
         }
         $countAll = 93;
         $countRemain = 93;
         if (($itemsFromBase = $this->wp->getOption('jigoshop_options_migrate_id')) !== false) {
             if ($itemsFromBase === '1') {
                 $countRemain = 0;
             }
         }
         $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll);
         if ($countRemain > 0) {
             if ($this->migrate()) {
                 $this->wp->updateOption('jigoshop_options_migrate_id', '1');
             } else {
                 $ajax_response['success'] = false;
                 Migration::saveLog(__('Migration coupons end with error.', 'jigoshop'));
             }
         } elseif ($countRemain == 0) {
             Migration::saveLog(__('Migration coupons END.', 'jigoshop'));
         }
         echo json_encode($ajax_response);
     } catch (Exception $e) {
         if (WP_DEBUG) {
             \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e);
         }
         echo json_encode(array('success' => false));
         Migration::saveLog(__('Migration options end with error: ', 'jigoshop') . $e);
     }
     exit;
 }
Example #2
0
 public function install()
 {
     $db = $this->wp->getOption('jigoshop_database_version');
     if ($db === false) {
         Registry::getInstance(JIGOSHOP_LOGGER)->addNotice('Installing Jigoshop.');
         $this->_createTables();
         $this->_createPages();
         $wpdb = $this->wp->getWPDB();
         $hasEmails = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = %s", array(Types::EMAIL))) > 0;
         if (!$hasEmails) {
             $this->installEmails();
         }
         foreach ($this->initializers as $initializer) {
             /** @var $initializer Core\Installer\Initializer */
             $initializer->initialize($this->wp);
         }
         $this->cron->clear();
     }
     // Flush rules on first Jigoshop init after activation.
     update_option('jigoshop_force_flush_rewrite', 1);
     $this->wp->updateSiteOption('jigoshop_database_version', self::DB_VERSION);
 }
Example #3
0
 public function ajaxMigrationProducts()
 {
     try {
         //			1 - if first time ajax request
         if ($_POST['msgLog'] == 1) {
             Migration::saveLog(__('Migration products START.', 'jigoshop'), true);
         }
         $wpdb = $this->wp->getWPDB();
         $productsIdsMigration = array();
         if (($TMP_productsIdsMigration = $this->wp->getOption('jigoshop_products_migrate_id')) === false) {
             $query = $wpdb->prepare("\n\t\t\t\tSELECT ID FROM {$wpdb->posts}\n\t\t\t\t\tWHERE post_type IN (%s, %s) AND post_status <> %s", 'product', 'product_variation', 'auto-draft');
             $products = $wpdb->get_results($query);
             $countMeta = count($products);
             for ($aa = 0; $aa < $countMeta; $aa++) {
                 $productsIdsMigration[] = $products[$aa]->ID;
             }
             $productsIdsMigration = array_unique($productsIdsMigration);
             $this->wp->updateOption('jigoshop_products_migrate_id', serialize($productsIdsMigration));
             $this->wp->updateOption('jigoshop_products_migrate_count', count($productsIdsMigration));
         } else {
             $productsIdsMigration = unserialize($TMP_productsIdsMigration);
         }
         $countAll = $this->wp->getOption('jigoshop_products_migrate_count');
         $singleProductId = array_shift($productsIdsMigration);
         $countRemain = count($productsIdsMigration);
         $query = $wpdb->prepare("\n\t\t\tSELECT DISTINCT p.ID, pm.* FROM {$wpdb->posts} p\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID\n\t\t\t\tWHERE p.post_type IN (%s, %s) AND p.post_status <> %s AND p.ID = %d", 'product', 'product_variation', 'auto-draft', $singleProductId);
         $product = $wpdb->get_results($query);
         $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll);
         if ($singleProductId) {
             if ($this->migrate($product)) {
                 $this->wp->updateOption('jigoshop_products_migrate_id', serialize($productsIdsMigration));
             } else {
                 $ajax_response['success'] = false;
                 Migration::saveLog(__('Migration products end with error.', 'jigoshop'));
             }
         } elseif ($countRemain == 0) {
             $this->wp->updateOption('jigoshop_products_migrate_id', serialize($productsIdsMigration));
             $this->wp->deleteOption('jigoshop_attributes_anti_duplicate');
             Migration::saveLog(__('Migration products END.', 'jigoshop'));
         }
         echo json_encode($ajax_response);
     } catch (Exception $e) {
         if (WP_DEBUG) {
             \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e);
         }
         echo json_encode(array('success' => false));
         Migration::saveLog(__('Migration products end with error: ', 'jigoshop') . $e);
     }
     exit;
 }
Example #4
0
 public function ajaxMigrationEmails()
 {
     try {
         //			1 - if first time ajax request
         if ($_POST['msgLog'] == 1) {
             Migration::saveLog(__('Migration emails START.', 'jigoshop'), true);
         }
         $wpdb = $this->wp->getWPDB();
         $query = $wpdb->prepare("\n\t\t\t\tSELECT DISTINCT p.ID, pm.* FROM {$wpdb->posts} p\n\t\t\t\tLEFT JOIN {$wpdb->postmeta} pm ON pm.post_id = p.ID\n\t\t\t\t\tWHERE p.post_type IN (%s) AND p.post_status <> %s", array('shop_email', 'auto-draft'));
         $emails = $wpdb->get_results($query);
         $joinEmails = array();
         $emailsIdsMigration = array();
         for ($aa = 0; $aa < count($emails); $aa++) {
             $joinEmails[$emails[$aa]->ID][$emails[$aa]->meta_id] = new \stdClass();
             foreach ($emails[$aa] as $k => $v) {
                 $joinEmails[$emails[$aa]->ID][$emails[$aa]->meta_id]->{$k} = $v;
                 $emailsIdsMigration[] = $emails[$aa]->ID;
             }
         }
         $emailsIdsMigration = array_unique($emailsIdsMigration);
         $countAll = count($emailsIdsMigration);
         if (($TMP_emailsIdsMigration = $this->wp->getOption('jigoshop_emails_migrate_id')) !== false) {
             $emailsIdsMigration = unserialize($TMP_emailsIdsMigration);
         }
         $singleEmailsId = array_shift($emailsIdsMigration);
         $countRemain = count($emailsIdsMigration);
         sort($joinEmails[$singleEmailsId]);
         $ajax_response = array('success' => true, 'percent' => floor(($countAll - $countRemain) / $countAll * 100), 'processed' => $countAll - $countRemain, 'remain' => $countRemain, 'total' => $countAll);
         if ($singleEmailsId) {
             if ($this->migrate($joinEmails[$singleEmailsId])) {
                 $this->wp->updateOption('jigoshop_emails_migrate_id', serialize($emailsIdsMigration));
             } else {
                 $ajax_response['success'] = false;
                 Migration::saveLog(__('Migration emails end with error.', 'jigoshop'));
             }
         } elseif ($countRemain == 0) {
             $this->wp->updateOption('jigoshop_emails_migrate_id', serialize($emailsIdsMigration));
             Migration::saveLog(__('Migration emails END.', 'jigoshop'));
         }
         echo json_encode($ajax_response);
     } catch (Exception $e) {
         if (WP_DEBUG) {
             \Monolog\Registry::getInstance(JIGOSHOP_LOGGER)->addDebug($e);
         }
         echo json_encode(array('success' => false));
         Migration::saveLog(__('Migration emails end with error: ', 'jigoshop') . $e);
     }
     exit;
 }
Example #5
0
 /**
  * Loads proper template based on current page.
  *
  * @param $template string Template chain.
  *
  * @return string Template to load.
  */
 public function process($template)
 {
     if (!Pages::isJigoshop()) {
         return $template;
     }
     if ($this->page === null) {
         if (WP_DEBUG) {
             throw new Exception('Page object should already be set for Jigoshop pages, but none found.');
         }
         Registry::getInstance(JIGOSHOP_LOGGER)->addCritical('Page object should already be set for Jigoshop pages, but none found.');
         return false;
     }
     $content = $this->page->render();
     $template = $this->wp->getOption('template');
     $theme = $this->wp->wpGetTheme();
     if ($theme->get('Author') === 'WooThemes') {
         $template = 'woothemes';
     }
     if (!file_exists(\JigoshopInit::getDir() . '/templates/layout/' . $template . '.php')) {
         $template = 'default';
     }
     Render::output('layout/' . $template, array('content' => $content));
     return false;
 }
Example #6
0
 /**
  * Returns fields with active plugin data.
  *
  * @return array
  */
 private function getActivePlugins()
 {
     $activePlugins = (array) $this->wp->getOption('active_plugins', array());
     if (is_multisite()) {
         $activePlugins = array_merge($activePlugins, $this->wp->getSiteOption('active_sitewide_plugins', array()));
     }
     $fields = array();
     foreach ($activePlugins as $plugin) {
         $pluginData = @get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin);
         $versionString = '';
         $networkString = '';
         if (!empty($pluginData['Name'])) {
             // link the plugin name to the plugin url if available
             $pluginName = esc_html($pluginData['Name']);
             if (!empty($pluginData['PluginURI'])) {
                 $pluginName = '<a href="' . esc_url($pluginData['PluginURI']) . '" title="' . __('Visit plugin homepage', 'jigoshop') . '" target="_blank">' . $pluginName . '</a>';
             }
             $fields[] = array('id' => $plugin, 'name' => $plugin, 'title' => $pluginName, 'tip' => '', 'type' => 'constant', 'value' => sprintf(_x('by %s', 'by author', 'jigoshop'), $pluginData['Author']) . ' &ndash; ' . esc_html($pluginData['Version']) . $versionString . $networkString);
         }
     }
     return $fields;
 }
Example #7
0
 /**
  * Retrieves id of specified Jigoshop page.
  *
  * @param $page string Page slug.
  *
  * @return mixed Page ID.
  */
 public function getPageId($page)
 {
     return $this->wp->getOption('jigoshop_' . $page . '_id');
 }
Example #8
0
 /**
  * @param $order Order The order.
  *
  * @return array Available arguments with proper values.
  */
 private function getOrderEmailArguments($order)
 {
     $billingAddress = $order->getCustomer()->getBillingAddress();
     $shippingAddress = $order->getCustomer()->getShippingAddress();
     return $this->wp->applyFilters('jigoshop\\emails\\order_variables', array('blog_name' => $this->wp->getBloginfo('name'), 'order_number' => $order->getNumber(), 'order_date' => $this->wp->getHelpers()->dateI18n($this->wp->getOption('date_format')), 'shop_name' => $this->options->get('general.company_name'), 'shop_address_1' => $this->options->get('general.company_address_1'), 'shop_address_2' => $this->options->get('general.company_address_2'), 'shop_tax_number' => $this->options->get('general.company_tax_number'), 'shop_phone' => $this->options->get('general.company_phone'), 'shop_email' => $this->options->get('general.company_email'), 'customer_note' => $order->getCustomerNote(), 'order_items' => $this->formatItems($order), 'subtotal' => ProductHelper::formatPrice($order->getSubtotal()), 'shipping' => ProductHelper::formatPrice($order->getShippingPrice()), 'shipping_cost' => ProductHelper::formatPrice($order->getShippingPrice()), 'shipping_cost_raw' => $order->getShippingPrice(), 'shipping_method' => $order->getShippingMethod() ? $order->getShippingMethod()->getName() : '', 'discount' => ProductHelper::formatPrice($order->getDiscount()), 'total_tax' => ProductHelper::formatPrice($order->getTotalTax()), 'total' => ProductHelper::formatPrice($order->getTotal()), 'is_local_pickup' => $order->getShippingMethod() && $order->getShippingMethod()->getId() == LocalPickup::NAME ? true : null, 'checkout_url' => $order->getStatus() == Order\Status::PENDING ? OrderHelper::getPayLink($order) : null, 'payment_method' => $order->getPaymentMethod()->getName(), 'billing_first_name' => $billingAddress->getFirstName(), 'billing_last_name' => $billingAddress->getLastName(), 'billing_company' => $billingAddress instanceof CompanyAddress ? $billingAddress->getCompany() : '', 'billing_address_1' => $billingAddress->getAddress(), 'billing_address_2' => '', 'billing_postcode' => $billingAddress->getPostcode(), 'billing_city' => $billingAddress->getCity(), 'billing_country' => Country::getName($billingAddress->getCountry()), 'billing_country_raw' => $billingAddress->getCountry(), 'billing_state' => Country::hasStates($billingAddress->getCountry()) ? Country::getStateName($billingAddress->getCountry(), $billingAddress->getState()) : $billingAddress->getState(), 'billing_state_raw' => $billingAddress->getState(), 'billing_email' => $billingAddress->getEmail(), 'billing_phone' => $billingAddress->getPhone(), 'shipping_first_name' => $shippingAddress->getFirstName(), 'shipping_last_name' => $shippingAddress->getLastName(), 'shipping_company' => $shippingAddress instanceof CompanyAddress ? $shippingAddress->getCompany() : '', 'shipping_address_1' => $shippingAddress->getAddress(), 'shipping_address_2' => '', 'shipping_postcode' => $shippingAddress->getPostcode(), 'shipping_city' => $shippingAddress->getCity(), 'shipping_country' => Country::getName($shippingAddress->getCountry()), 'shipping_country_raw' => $shippingAddress->getCountry(), 'shipping_state' => Country::hasStates($shippingAddress->getCountry()) ? Country::getStateName($shippingAddress->getCountry(), $shippingAddress->getState()) : $shippingAddress->getState(), 'shipping_state_raw' => $shippingAddress->getState()), $order);
 }